我有以下代碼:問題與加盟實體結果:未定義指數:ID在學說/ ORM/UnitOfWork.php
$rsm = new ResultSetMapping();
$rsm->addEntityResult('App\MainBundle\Entity\InstagramShopPicture', 'p');
$rsm->addFieldResult('p', 'id', 'id');
$rsm->addFieldResult('p','lowresimageurl','lowresimageurl');
$rsm->addFieldResult('p','medresimageurl','medresimageurl');
$rsm->addFieldResult('p','highresimageurl','highresimageurl');
$rsm->addFieldResult('p','caption','caption');
$rsm->addFieldResult('p','numberoflikes','numberoflikes');
$rsm->addFieldResult('p','numberofdislikes','numberofdislikes');
$rsm->addJoinedEntityResult('App\MainBundle\Entity\InstagramShop', 's', 'p', 'shop');
$rsm->addFieldResult('s', 'id', 'id');
$rsm->addFieldResult('s', 'username', 'username');
$query = $em->createNativeQuery('SELECT picture.id, picture.lowresimageurl, picture.medresimageurl, picture.highresimageurl, picture.caption, picture.numberoflikes, picture.numberofdislikes, shop.id AS shop_id , shop.username
FROM App_instagram_picture_category category
INNER JOIN App_instagram_shop_picture picture ON category.picture_id = picture.id
INNER JOIN App_instagram_shop shop ON shop.id = picture.shop_id
WHERE category.first_level_category_id = ?
AND picture.deletedAt IS NULL
AND shop.deletedAt IS NULL
AND shop.isLocked = 0
AND shop.expirydate IS NOT NULL
AND shop.expirydate > ?
AND shop.owner_id IS NOT NULL
GROUP BY shop.id
LIMIT ?'
, $rsm);
$query->setParameter(1, 10);
$query->setParameter(2, '2014-05-20');
$query->setParameter(3, 10);
$itemsFromDifferentShops = $query->getResult();
但是我經常收到以下錯誤/警告:
Notice: Undefined index: id in /Users/Alex/Sites/App/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 2433
這裏是我的實體是什麼樣子:
class InstagramShop
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* @var string
* @ORM\Column(name="username", type="string", nullable=true)
*/
private $username;
/**
* @Exclude()
* @ORM\OneToMany(targetEntity="InstagramShopPicture", mappedBy="shop", cascade=
{"persist"})
* @ORM\OrderBy({"createdtimestamp" = "DESC"})
*/
protected $userPictures;
}
class InstagramShopPicture
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Exclude()
* @ORM\ManyToOne(targetEntity="InstagramShop", inversedBy="userPictures")
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
protected $shop;
}
這是爲什麼?我如何解決它?我的懷疑是因爲有兩個ID。一個是產品ID,另一個是商店ID,兩者都有相同的參考。但我試圖改變它,它仍然給我警告。
'$ rsm-> addFieldResult('p','id','id');'它指着這條線坐嗎? – Viscocent
@Viscocent我不知道,當我刪除addJoinedEntityResult和它下面的兩行時,它工作正常,我認爲錯誤與$ rsm-> addFieldResult('s','id','id')有關; – adit
在你的「InstagramShop」表中,你真的有一個字段ID? – Viscocent