While migrating the EFQ code in #1188388: Entity translation UI in core to EFQ2 I stumbled upon this: I needed to count the number of field values for a certain field, which may be shared among different entities (this is the scenario I was using for testing). The count query always returned the total number of values no matter which entity type the entity query was concerning: if I had 3 values, one for nodes, one for comments and one for taxonomy the count query returned 3 for all the entity types instead of one.

Comments

plach’s picture

Title: Entity query count not working with fields shared among different entities » Entity count query not working with fields shared among different entities
Status: Active » Needs review
StatusFileSize
new1.84 KB

It seems we are missing an entity type condition in the SQL query.

plach’s picture

Title: Entity count query not working with fields shared among different entities » Entity count query not working with fields shared among different entity types

Better title

chx’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Great find.

fabianx’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Status: Needs review » Needs work
Issue tags: +Needs tests

The last submitted patch, eq-count_shared_fields-1828790-1.patch, failed testing.

chx’s picture

You need to add to the join condition otherwise LEFT JOINs break.

plach’s picture

StatusFileSize
new1.99 KB

This should be ok, still needs tests though.

plach’s picture

Status: Needs work » Needs review
chx’s picture

pfrenssen is working on a test (and I am helping).

plach’s picture

FWIW #9 actually fixed the OP case.

Status: Needs review » Needs work
Issue tags: -Needs tests

The last submitted patch, eq-count_shared_fields-1828790-7.patch, failed testing.

fabianx’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
pfrenssen’s picture

Here's what I have so far. This still needs work but the office I'm working at is closing. I'm continuing tomorrow.

chx’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.57 KB
new3.56 KB

As I did little more than adding an assert and comments #13 and added #7 I don't feel I am RTBC'ing my own.

chx’s picture

StatusFileSize
new3.48 KB

Even better comments after talking to plach.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

yesct’s picture

Status: Fixed » Needs review
Issue tags: -Needs tests

#15: 1828790_15.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs tests

The last submitted patch, 1828790_15.patch, failed testing.

pfrenssen’s picture

Status: Needs work » Fixed

This has already been committed, it is not necessary to test the patch any more.

Automatically closed -- issue fixed for 2 weeks with no activity.