You tried to define the $ delegation property, for example
/** * @ORM\ManyToOne(targetEntity="Delegation", inversedBy="promotions") * @ORM\JoinColumn(name="delegation_id", referencedColumnName="id") */ private $delegation;
See Doctrine2 Docs: Map Mapping -> Multi-to-One
There are also many typos in your code. for instance
/** * @ORM\OneToMany(targetEntity="Promotion", mappedBy="delegacion", cascade={"all"}, orphanRemoval=true) */ protected $promotions;
mappedBy="delegacion" must be mappedBy="delegation" .
or
public function getDeleTacion() { return $this->deleTacion; }
Must be
public function getDelegation() { return $this->delegation; }
Edit
Well, I created for you a minimalist version that worked for me. You can create it there or watch the differences with your code:
Promotion.php
use Doctrine\ORM\Mapping as ORM; class Promotion { protected $id; public $delegation; public $product; }
Delegation.php
use Doctrine\ORM\Mapping as ORM; class Delegation { protected $id; public $promotions; public function __construct() { $this->promotions = new \Doctrine\Common\Collections\ArrayCollection(); } }
product.php
use Doctrine\ORM\Mapping as ORM; class Product { protected $id; public $promotions; public function __construct() { $this->promotions = new \Doctrine\Common\Collections\ArrayCollection(); } }
If you are now doing something like
$delegation = new Delegation(); $product = new Product(); $promotion = new Promotion(); $promotion->delegation = $delegation; $promotion->product = $product; $em->persist($promotion); $em->flush(); $products = $em->createQuery('select p from BundleName\Entity\Product p')->execute(); $delegations = $em->createQuery('select d from BundleName\Entity\Delegation d')->execute(); var_dump(count($products[0]->promotions), count($delegations[0]->promotions));
In the end, you should
int(1) int(1)
Thus, refrence is actually saved and can be read. Phew Good luck with that!: -)