ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

Forums OroPlatform OroPlatform – How do I? Questions Many-To-Many relation between User and Custom entities

This topic contains 5 replies, has 4 voices, and was last updated by  archy_bold 2 years, 1 month ago.

  • Creator
    Topic
  • #62466

    maksold
    Participant

    I need to create Many-To-Many relation between User and Room (custom extended entity) entities. Then I need to display grid with Users on Room update page, and grid with Rooms on User update page. I have 2 ideas how to do that, but in each of them I had problems.

      Create migration script and add entity via ->addManyToManyRelation(). – But here I faced with problem, that I use e.g. User->getRooms(), because I can’t add this function to User entity class.
      Rewrite OroUserBundle and rewrite User entity class. – But here I faced with problem, that when I copy /Entity/User.php file to my custom bundle and when I run php app/console doctrine:schema:update --dump-sql, it display error, that ‘oro_user’ table already exist.

    What is the best way to add Many-To-Many relation between User and Custom entities?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #62467

    Vova Soroka
    Participant

    Hello,

    The right way is to create extended many-to-many relation in a migration script.
    The ExtendExtension::addManyToManyRelation is intended to do it. But in your case you need bidirectional relation, because you want to display related entities on both owning and target sides.
    Unfortunately, it is not possible to create a bidirectional relation using a migration script. I’ve reported this issue. We’ll try to prepare a fix ASAP.

    #62468

    musicthebee
    Participant

    Hi

    Any update on this? I am running into the same issue with a build from November and wondering if this has been fixed in the latest source.

    Thanks
    M

    #62469

    archy_bold
    Participant

    This is also something that’s tripped me up. An update on how to achieve it would be great.

    #62470

    Vova Soroka
    Participant

    Hi all,

    Sorry for the late message.
    The bidirectional relations have been already implemented. Please see details in https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/EntityExtendBundle/Resources/doc/relations.md

    #62471

    archy_bold
    Participant

    Ah cool. Is there more to adding relations through the EntityExtendBundle? I’ve managed to add the relation but when I call getSubscriptions on my model, I always get null. Even with data in the database.

    Should the extended model have annotations for Doctrine or do I need to define them in my own model?

    My extended entity class looks as follows:

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

You will be redirected to [title]. Would you like to continue?

Yes No
ssossossosso