This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal

eZ Community » Forums » Developer » Relation between user and another...

Relation between user and another bundle's entity

Relation between user and another bundle's entity

Wednesday 22 April 2015 9:14:49 pm - 3 replies


After several days trying to make a relation between my Symfony bundle and the Ez Publish user, I ended by posting this issue in the forum.

In my case I have a test bundle where users can pass a test, so I want to to make a fieldtype relation like: 

*@ORM\ManyToOne(targetEntity="Test", inversedBy="user" )

*@ORM\JoinColumn(name="test_id", referencedColumnName="id", onDelete="SET NULL" )    


Thank you for your help.

Modified on Wednesday 22 April 2015 9:22:27 pm by Moize Laanait

Thursday 23 April 2015 9:35:45 am


maybe someone else has a cleaner solution but you can try this :

  • In your entity create two fields $user and $userId
  • Your client classes should only manipulate $user
  • Map only $userId to a column
  • Create a Doctrine Listener doing something like this:
    • onPrePersist : $entity->setUserId( $entity->getUser()->id )
    • onPostLoad : $entity->setUser( $this->userService->loadUser( $entity->getUserId() )

Note that there should be some permissions related gotchas to deal with though (can current user read related user?).

Hope this helps.

Friday 24 April 2015 8:44:22 am

Interesting, Ben !

Permissions should be fine, since UserService::loadUser() will throw an exception if the currently logged in user doesn't have the required permissions.

Monday 27 April 2015 9:43:04 am


I noticed yesterday that this question is also cross posted on StackOverflow:



You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from