Doctrine 2 one-to-one via composite key

狂风中的少年 提交于 2019-12-10 15:43:48

问题


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.



来源:https://stackoverflow.com/questions/8356848/doctrine-2-one-to-one-via-composite-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!