OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM OroCRM – How do I? Questions Datagrid using one of "oro_rel_…" table.

This topic contains 2 replies, has 2 voices, and was last updated by  czaros45 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
  • #29383

    czaros45
    Participant

    Hi everyone,

    I need to make a datagrid with customers and their activities. I would like to see something like that:

    Name of the customer:_________Number of activities:
    CustomerA __________________________3
    CustomerB __________________________5

    I found a table called: oro_rel_c3990ba6784fec5f23d770 and it solves my problem since it stores relation between customer_id and activity_id.
    My approach would be like this:
    1. Code a method which contains DQL query where I hardcode this name (it feels like it’s a not right way to do it)
    2. According to this documentation I can make a class a service and use it in “query” field in datagrid: https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/DataGridBundle/Resources/doc/backend/datagrid.md

    I’m forced to do it with a service because this:

    calls that Class oro_rel_c3990ba6784fec5f23d770 does not exist.

    My questions are:
    – Is it simplier solution to this that I’m missing?
    – How to get the name of the table in not hardcoded way? I found a Class ExtendDbIdentifierNameGenerator.php and a method generateManyToManyJoinTableName() which generates this name, although I cannot find a way to retrieve that name.

    Thanks in advance.
    Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #29384

    ypetrov
    Participant

    Hello, czaros45
    1) You are right you can’t use table name, it should be entity name
    2) In your example you are using only one table ManyToMany, here we can see that Account has at least two types of activities

    So I would recommend you to create listener for data grid on event “onResultAfter” and add column to result set.
    Count of all activities can be fetched from ActivityRepository for your case it will be great create query that will work with array of accounts.

    Or another way your can try to create listener on event ‘onBuildAfter’ and implement similar query from ActivityRepository at datagrid config but it wont be easy

    #29385

    czaros45
    Participant

    Hi ypetrov,

    I created listener for data grid on event “onResultAfter” and for each record I calculated activities count and added them to the column. Your approach worked :) Thank you for your answer!

    Cheers.

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

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

Back to top