dongzhi1904 2015-04-10 04:56
浏览 42

为什么我在加入两个表时无法在Doctrine中获取实体

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动