このタイプの関係はたくさんありますが、なぜこれが機能しないのかわかりません。
Delegation と Promotion エンティティがあります:
Delegation
昇進
/**
* Company\CBundle\Entity\Promotion
*
* @ORM\Entity
* @DoctrineAssert\UniqueEntity("promotionCode")
*/
class Promotion
{
const REGISTER_DAYS = 30;
const REGISTER_DISCOUNT = 100;
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="promotionCode", type="string", unique=true, nullable=true)
*/
protected $promotionCode;
/**
* @ORM\Column(name="name", type="string")
*/
protected $name;
/**
* @ORM\Column(name="description", type="string", nullable=true)
*/
protected $description;
/**
* @ORM\Column(name="days", type="integer")
*/
protected $days;
/**
* @ORM\Column(name="discount", type="float")
*/
protected $discount;
/**
* @ORM\ManyToOne(targetEntity="Delegation", inversedBy="promotions")
* @ORM\JoinColumn(name="delegation_id", referencedColumnName="id")
*/
private $delegation;
/**
* @ORM\ManyToOne(targetEntity="Product", inversedBy="promotions")
*/
private $product;
/**
* @var date $adquiredDate
*
* @ORM\Column(name="adquiredDate", type="date", nullable=true)
*/
private $adquiredDate;
コントローラーでプロモーションを作成すると、テーブル Promotion には委任オブジェクトに関連する新しいオブジェクトがあります
private function createPromotion($delegation)
{
$em = $this->getDoctrine()->getEntityManager();
$promotion = Promotion::createPromotion($delegacion, Promotion::REGISTER_DAYS, Promotion::REGISTER_DISCOUNT);
$em->persist($promotion);
$em->persist($delegation);
$em->flush();
}
データベース
*************************** 15. row ***************************
id: 32
delegation_id: 19
days: 20
discount: 50
adquiredDate: 2013-01-10
*************************** 16. row ***************************
id: 33
delegation_id: 19
days: 25
discount: 50
adquiredDate: 2013-01-10
*************************** 17. row ***************************
id: 34
delegation_id: 19
days: 30
discount: 50
adquiredDate: 2013-01-10
しかし、別のコントローラー/アクションで $delegation->getPromotions() を呼び出すと、プロモーションはなく、データのない Doctrine\ORM\PersistentCollection が返されます。
誰か助けてくれませんか?
詳細情報を編集します。$delegation->getPromotions() は空ですが、その委任のプロモーションを探して $promotion->getDelegation() を呼び出すと、委任が正しく返されます:?