Here is some info of models my entitys class :
EquipmentDetail Entity
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Application\Entity\EquipmentDetail
*
* @ORM\Table(name="EQUIPMENT_DETAIL")
* @ORM\Entity
*/
class EquipmentDetail extends \Application\Entity\Base\BaseEntity
{
/**
* @var integer $equipmentDetailId
*
* @ORM\Column(name="EQUIPMENT_DETAIL_ID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $equipmentDetailId;
/**
* @var string $description
*
* @ORM\Column(name="DESCRIPTION", type="text", nullable=true)
*/
private $description;
/**
* @var integer $active
*
* @ORM\Column(name="ACTIVE", type="integer", nullable=true)
*/
private $active;
/**
* @var Application\Entity\Equipment
*
* @ORM\ManyToOne(targetEntity="Application\Entity\Equipment")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="EQUIPMENT_ID", referencedColumnName="EQUIPMENT_ID")
* })
*/
private $equipment;
/**
* @var Application\Entity\EquipmentProperty
*
* @ORM\ManyToOne(targetEntity="Application\Entity\EquipmentProperty")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="EQUIPMENT_PROPERTY_ID", referencedColumnName="EQUIPMENT_PROPERTY_ID")
* })
*/
private $equipmentProperty;
I also have
\Application\Entity\Base\BaseEntity
and
\Application\Entity\EquipmentProperty
All of model class is return true entity class and it work well in other case.
and it work fine in other case, example :
$propertyType = $this->getTypePropertyModel()->createQueryBuilder('t')->join('t.equipmentType', 'eq')
->where('eq.equipmentTypeId=:typeId')->setParameter('typeId', $typeId)->getQuery()->getResult();
But when i create querybuilder and join two table, i can't get result. I have tried many ways below :
$detail = $this->getEquipmentDetailModel()->getEntityManager()
->createQuery('SELECT d FROM \Application\Entity\EquipmentDetail d '
. 'JOIN d.equipment e JOIN d.equipmentProperty ep '
. 'WHERE (e.equipmentId = 3130'
. 'AND ep.equipmentPropertyId =2'
. '')
->getResult();
or
$detail = $this->getEquipmentDetailModel()->findBy(array('equipment' => 3130, 'equipmentProperty' => 2));
or
$detail = $this->getEntityManager()->createNativeQuery('SELECT DESCRIPTION FROM EQUIPMENT_DETAIL e WHERE e.EQUIPMENT_ID = 3130 AND e.EQUIPMENT_PROPERTY_ID =2;', $rsm)->getResult();
or
$detail = $this->getEquipmentDetailModel()->createQueryBuilder('d')
->innerJoin('d.equipment', 'e')
->innerJoin('d.equipmentProperty', 'ep')
->where('e.equipmentId = :ID')
->andWhere('ep.equipmentPropertyId =:epID')
->setParameter('ID', 3130)
->setParameter('epID', 2)
->getQuery()->setMaxResults(1)->getResult();
and i get error
"Fatal error: Call to a member function getDescription() on a non-object in...."
when call $detail->getDescription(). I am sure that, i have record EQUIPMENT_DETAIL in my database with info :
EQUIPMENT_DETAIL_ID : 45
EQUIPMENT_ID : 3130
EQUIPMENT_PROPERTY_ID : 2
DESCRIPTION :Olala
ACTIVE : 1
Every thing is well when i use :
$detail = $this->getEquipmentDetailModel()->find(45);
Plese tell me why i can't get result or if i given not enough information.