Doctrine 2 one-to-one via composite key

2019-06-25 09:44发布

问题:

I am trying to set up a relationship as shown below. Each car can have one review. A car has a primary key on 2 columns. Review is referenced back to the car via the composite primary key. Simple, in theory.

class Car {

    /**
     * @ORM\Id
     * @ORM\Column(type="string")
     */
    private $make;

    /**
     * @ORM\Id
     * @ORM\Column(type="string")
     */
    private $model;

    /**
     *
     * @ORM\OneToOne(targetEntity="Review", mappedBy="car", cascade={"persist"})
     */
    private $review;
}




class Review {
    /**
     * @ORM\Id
     * @ORM\OneToOne(targetEntity="Car", inversedBy="review")
     */
    private $car;

    /**
     * @var @ORM\Column(type="text")
     */
    private $text;
}

When I try to generate the schema, the following error pops up.

Column name id referenced for relation from \Entity\Review towards \Entity\Car does not exist.

What am I doing wrong?

回答1:

After extensive research, I can say that the above structure is not supported by Doctrine, unfortunately.