Updated Sep 14th, 2012
Symfony Db

Rules

OneToMany must have mappedBy

One to Many

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;

Saving

$em = $this->getDoctrine()->getEntityManager(); $em->persist($result); $em->flush();