Skip to content

Count is not made on the primary column when it is in a joined table. #962

Open

Description

@MaxandreOgeret

Hello everyone.

I have a problem and I can't solve it.
I have to display a grid, containing datas from a table and a joined table.
The primary column is set correctly, but the count query is not made on this column ! It is made on the id of the first table !

Why should the primary column not be used to count? I don't understand. Is it a bug?

SELECT count(DISTINCT h0_.id) AS sclr_0 FROM hierabc h0_ INNER JOIN AdresseAll a1_ ON (h0_.idpeople= a1_.idpeople) WHERE h0_.idpeoplesup= ('XXXXXXXXXXX'');
Here h0.id, is the id of the entity selected as source. But it is not the column set as primary.

Don't hesitate to ask me anything if you need further details!

Thanks a lot for your help !!

Activity

  1. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    Hello, I'm trying to investigate it but, conceptually, isn't the result the same?
    If a row is filtered out by join condition, it will not appear. If it is in there, you can count on pretty much every (unique) column.

    In your case is not id a unique field so the count is not properly reported?

  2. MaxandreOgeret commented on Jul 28, 2017

    @MaxandreOgeret
    Author

    Thanks for your answer.

    No, the result was not the same, as the count is a count distinct.

    [001|value1]
    [001|value2]
    [002|value3]
    [002|value4]

    This will only count 2, while it should count 4.

  3. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    Ok, so because it's not a unique value field where value* is; am I right?

  4. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    What is your Source? Entity?

  5. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    @MaxandreOgeret check this out https://github.com/APY/APYDataGridBundle/blob/58f4e370ba79bd7d593a3759010ab002b3946b61/Resources/doc/columns_configuration/annotations/column_annotation_property.md

    Note 4: If you have and id field and want to use another field as primary, you need to set primary=false on the id field.

  6. MaxandreOgeret commented on Jul 28, 2017

    @MaxandreOgeret
    Author

    Yes you're right. and my source is an entity

    Setting the field as primary do not work with the count query. The count walker, takes the primary key of the source entity, not the column set as primary.

  7. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    @MaxandreOgeret follow my last comment, it should resolve your issue.

  8. MaxandreOgeret commented on Jul 28, 2017

    @MaxandreOgeret
    Author

    I tried, but it don't change anything. :/

  9. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    Can you show me relevant code?

  10. MaxandreOgeret commented on Jul 28, 2017

    @MaxandreOgeret
    Author

    I don't have the sources right now, but i'll try to give you an exemple.

    I have two tables :

    [---CUSTOMER---]
    [ID |NAME |LEVEL]
    [001|value1| 01]
    [002|value2| 02]
    [003|value3| 02]
    [004|value4| 03]
    [005|value5| 03]
    [006|value6| 03]
    [007|value7| 03]

    [---------CUSTOMER-TREE---------]
    [CUSTOMER ID|PARENT CUSTOMER]
    [ 002| 001]
    [ 003| 001]
    [ 004| 002]
    [ 005| 002]
    [ 006| 003]
    [ 007| 003]

    These tables represents this tree :

                1
               /  \
             2     3
           /  \    /  \
          4   5  6   7
    

    Let's say customers have more than one adresses and i want to list those adresses like :

    [max_parent|customer| adress]
    [ 01| 01| adress1]
    [ 01| 02| adress2]
    [ 01| 03| adress3]
    [ 01| 04| adress4]
    [ 01| 05| adress5]
    [ 01| 06| adress6]
    [ 01| 07| adress7]

    If my primary entity is CUSTOMER and max_parent comes from it, it will count only one.

    Tell me if you want more explanations.

  11. MaxandreOgeret commented on Jul 28, 2017

    @MaxandreOgeret
    Author

    You may just check that the count request is made on the column marked as primary.

  12. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    I understand.
    Let me tackle this (hopefully) in the next days: I'll try to reproduce it and let you know.

    BTW I can't guarantee that I'll take a look soon as from today I'm in vacation :)

    Last question: can you tell me what source are you using? Entity, Document (Mongo) or Vector as grid source?

  13. MaxandreOgeret commented on Jul 28, 2017

    @MaxandreOgeret
    Author

    I am using Entity as grid source, thanks you :)

  14. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    @MaxandreOgeret can you show me how did you excluded id as primary field? Moreover, as things goes in session, have you tried to exclude it, logoff, login and check again?
    Could you, please, execute what I'm suggesting and report the results and annotation on Entity to exclude id as primary field?

  15. MaxandreOgeret commented on Jul 28, 2017

    @MaxandreOgeret
    Author

    I tried :
    $grid->getColumn('id')->setPrimary(false);
    I also tried via annotations.
    Yes i tried to log again too.

    I tried to dump the column and the attribute primary id expectedly false.

  16. DonCallisto commented on Jul 28, 2017

    @DonCallisto
    Member

    Ok, thank you.
    I need to take a look at this so.

    Once bug is confirmed, I will change the label and try to tackle it.

    Thanks for the moment.

  17. MaxandreOgeret commented on Jul 28, 2017

    @MaxandreOgeret
    Author

    I'm at your service if further investigations are required. Thanks for the moment too. 🥇

  18. MaxandreOgeret commented on Aug 1, 2017

    @MaxandreOgeret
    Author

    THis may help you

    count

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions