Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine- one of associations doesn't work proper
    primarykey
    data
    text
    <p>I have problem with associations in Doctrine 2 I have two associations which look the same. One works fine, the second one work in weird way. I'll explain it a bit later.</p> <p>Here is my main entity- Product:</p> <pre><code>** * Product * * @ORM\Table(name="product", indexes={ * @ORM\Index(name="category_index", columns={"category_id"}), * @ORM\Index(name="partner_index", columns={"partner_id"}) * }) * @ORM\Entity */ class Product { /** * @var integer * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string * * @ORM\Column(name="name", type="string", length=255, nullable=false) */ private $name; /** * @var Category * * @ORM\ManyToOne(targetEntity="Category") * @ORM\JoinColumn(name="category_id", referencedColumnName="id") */ private $categoryId; /** * @var Partner * * @ORM\ManyToOne(targetEntity="Partner") * @ORM\JoinColumn(name="partner_id", referencedColumnName="id") */ private $partnerId; } </code></pre> <p>Category Entity:</p> <pre><code>/** * Category * * @ORM\Table(name="category") * @ORM\Entity */ class Category { /** * @var integer * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string * * @ORM\Column(name="category_name", type="string", length=100, nullable=false) */ private $categoryName; } </code></pre> <p>Partner Entity:</p> <pre><code>/** * Partner * * @ORM\Table(name="partner") * @ORM\Entity */ class Partner { /** * @var integer * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string * * @ORM\Column(name="name", type="string", length=150, nullable=false) */ private $name; } </code></pre> <p>As you can see I have two identical associations:<br> Product#categoryId<br> Product#partnerId</p> <p>The first one- categoryId works as it should, but the second one- partnerId doesn't: </p> <p>First thing I noticed is that Doctrine create proxy class with Partner Entity, while Category Entity doesn't need proxy class to work, so one of this doesn't work proper.I just started with Doctrine so I might be wrong.</p> <p>I have 4 records in Partner table. When I try to modify Product record manually, in partner_id field I can't set 1-4, I can set something like this: </p> <pre><code>(empty) 1 - 1 2 - 2 3 - 3 4 - 4 (empty) 1 - 1 2 - 2 3 - 3 4 - 4 </code></pre> <p>First time I see something like this. </p> <p>And the last thing I noticed:</p> <pre><code>$query = $em-&gt;createQuery(' SELECT pp.name, p.id FROM Application\Entity\Product AS p LEFT JOIN Application\Entity\Partner AS pp WITH p.partner_id = pp.id GROUP by p.partner_id '); $items = $query-&gt;getResult(); </code></pre> <p>Shows me error:</p> <pre><code>Doctrine\ORM\Query\QueryException: [Semantical Error] line 0, col 148 near 'partner_id =': Error: Class Application\Entity\Product has no field or association named partner_id in </code></pre> <p>Thanks for any help and tips.</p> <p><strong>Edit</strong><br> So, the question is. Why does Doctrine create proxy class for Partner Entity, but not for Category?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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