0

I'm using Doctrine 2. I have an associative entity which points to two entities. Both are part of the composite key.

My problem is that JoinColumn only allows to specify the physical name, not the logical name. I need the two to be different. Everything else can be mapped, so I feel like I missed something.

/** * @ORM\Entity() * @ORM\Table(name="user_friend") */ class UserFriend { /** * @ORM\Id * @ORM\ManyToOne(targetEntity="User", inversedBy="friends") * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) **/ private $user; /** * @ORM\Id * @ORM\ManyToOne[...] **/ private $friend; private $connectedDate; } 

By the way, I tried separating the relationships from the id columns (user, userId), but that caused problems with cascade persists.

Any solution or perhaps a different route would be appreciated.

7
  • what do you mean by "physical name and logical name"? Commented Oct 7, 2015 at 18:09
  • @xurshid29 Physical name is the one in the actual database, logical name is the one in your code, hence the mapping. Commented Oct 8, 2015 at 0:24
  • What name exactly do you want to change? The thing that corresponds to user_id is UserFriend->user->id . There is no UserFriend->userId in the code. Commented Oct 8, 2015 at 7:28
  • @greg0ire I was hoping not being forced to do an extra join in my query to get the user's id. Doing a join (userFriend.user) to fetch just the ID that I already possess in an unnecessary step. If I understand correctly, there's no way to map the user_id column in this associative entity? Commented Oct 8, 2015 at 13:02
  • I don't think so, no. But maybe doctrine is clever enough to get the id from the user_id column when you call userFriend.user. BTW, you should probably rename UserFriend to FriendShip, it makes things easier to understand IMHO Commented Oct 8, 2015 at 16:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.