0

I have a table where two fields must be linked with Product entity. But Doctrine recognizes only one of them, processing second as usual integer.

I've read an almost similar question Doctrine2 Mapping: 2 fields mapped to one field (ManyToOne) but as far as I can see, my annotations must be correct.

Any ideas what am I doing wrong?

class ProductProduct:

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     */
    private $id;


    /**
    *  @ORM\Column(name="product_id", type="integer")
     * @ORM\ManyToOne(targetEntity="Product", inversedBy="productProduct")
     * @ORM\JoinColumn(name="product_id", referencedColumnName="id")
     */
    private $product;

    /**
     * @ORM\Column(name="product_replace_id", type="integer")
     * @ORM\ManyToOne(targetEntity="Product", inversedBy="productProductReplace")
     * @ORM\JoinColumn(name="product_replace_id", referencedColumnName="id")
     */
    private $productIdReplace;

class Product:

/**
 * @ORM\OneToMany(targetEntity="ProductProduct", mappedBy="product")
 **/
private $productProduct;

/**
 * @ORM\OneToMany(targetEntity="ProductProduct", mappedBy="productIdReplace")
 **/
private $productProductReplace;
Community
  • 1
  • 1
globox
  • 13
  • 5

1 Answers1

0

Damn, the problem was in the following lines:

@ORM\Column(name="product_replace_id", type="integer")

Seems like that annotation was dominating, overwriting @JoinColumn one. I deleted those lines in both entities and all seems to work now. Hope this question will help someone to avoid such simple bugs :)

globox
  • 13
  • 5