OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – How do I? Questions How to show ManyToMany in datagrid

This topic contains 1 reply, has 2 voices, and was last updated by  dkrushelnytskyi@magecore.com 6 years, 7 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #36494

    oro6
    Participant

    Hello,

    Lets say I have an entity Customer which has a ManyToMany relation to entity Adress. These get fetched via EAGER in Doctrine, so if I dump the entity, it already includes all the addresses.

    How can I show one field of the first address in the datagrid without doing an extra join over the address table? Reason: This gets extremely slow when there are a lot of entries.

    I tried to get the entity in a BuildAfterListener but this gives no results … any hints?

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #36495

    Hello,

    Platform does not have functionality to simple show many to many relation in grid column,
    but has example which may to help implement it for your case.

    Platform has bundle TagBundle. Tag entity has “many to many” relation with other entities and in the TagBundle there is implemented solution to show tags in the grids (For example, account, contact girds).

    May be this example will help you to solve issue.

    How it works.

    TagBundle has Oro\Bundle\TagBundle\Grid\TagsExtension with methods
    – processConfigs modifies grids definition to add the column “tags” in grids.
    https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/TagBundle/Grid/TagsExtension.php#L110

    – visitResult adds tags data in rows which should be show on the page.
    https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/TagBundle/Grid/TagsExtension.php#L207

    Loading data for grid is executed in Oro\Bundle\DataGridBundle\Datagrid\Datagrid by method getData.

    https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/DataGridBundle/Datagrid/Datagrid.php#L84-L93

    $rows = $this->getAcceptedDatasource()->getResults(); returns rows without data about tags.

    Then $this->acceptor->acceptResult($result); applies available extensions for selected rows.
    One of extensions it is TagsExtension which adds information about tags in results.

    This approach will not be gets extremely slow when there are a lot of entries.

Viewing 1 replies (of 1 total)

The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.

Back to top