OneToMany must have mappedBy
use Doctrine\Common\Collections\ArrayCollection;
@ORM\OneToMany(targetEntity="Product", mappedBy="category") protected $products;
public function __construct() { $this->products = new ArrayCollection(); }
// src/Acme/StoreBundle/Entity/Product.php
/** * @ORM\ManyToOne(targetEntity="Category", inversedBy="products") * @ORM\JoinColumn(name="category_id", referencedColumnName="id") */ protected $category;
$em = $this->getDoctrine()->getEntityManager(); $em->persist($result); $em->flush();