Symfony ONE-TO-ONE relation

后端 未结 1 735
被撕碎了的回忆
被撕碎了的回忆 2021-01-11 15:48

I am new to symfony2 and have trouble to do a left join between 2 entities. I\'m getting following error message, and don\'t know how to solve this problem:

相关标签:
1条回答
  • 2021-01-11 16:35

    I think the querybuilder looks alright. Your problem is likely in the data structure.

    The way you normally approach this is by setting up a property per relation. For your Users class it'd make sense to have an information or userInformation one for example.

    Perhaps something like this helps?

    class User
    {
        /**
         * @ORM\Id
         */
        protected $id;
    
        /**
         * @ORM\OneToOne(targetEntity="UserInformation")
         */
        protected $information;
    }
    
    class UserInformation
    {
        /**
         * @ORM\Id
         */
        protected $id;
    
        /**
         * @ORM\OneToOne(targetEntity="User", inversedBy="information")
         * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
         */
        protected $user;
    }
    
    0 讨论(0)
提交回复
热议问题