Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You just have to add a relation between your user and your product. So your Product entity should be like this :</p> <p><strong>src/Acme/MainBundle/Entity/Product.php</strong></p> <pre><code>namespace Acme\MainBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="product") */ class Product { /** * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=100) */ protected $name; /** * @ORM\Column(type="decimal", scale=2) */ protected $price; /** * @ORM\Column(type="text") */ protected $description; /** * @ORM\ManyToOne(targetEntity="Acme\UserBundle\Entity\User", inversedBy="products") * @ORM\JoinColumn(name="user_id", nullable=false) */ protected $user; } </code></pre> <p>And your user entity</p> <p><strong>src/Acme/UserBundle/Entity/User.php</strong></p> <pre><code>namespace Acme\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Acme\MainBundle\Entity\Product; /** * @ORM\Entity * @ORM\Table(name="user") */ class User { /**- * User properties... */ /** * @ORM\OneToMany(targetEntity="Acme\MainBundle\Entity\Product", mappedBy="user", cascade={"remove"}) */ protected $products; /** * Constructor */ public function __construct() { $this-&gt;products = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Add product * * @param Product $product * @return Branch */ public function addProduct(Product $product) { $this-&gt;products[] = $product; return $this; } /** * Remove product * * @param Product $products */ public function removeProduct(Product $product) { $this-&gt;products-&gt;removeElement($product); } /** * Get products * * @return \Doctrine\Common\Collections\Collection */ public function getProducts() { return $this-&gt;products; } } </code></pre> <p>Everything is explain in the <a href="http://docs.doctrine-project.org/en/latest/reference/association-mapping.html" rel="nofollow">doctrine documentation</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload