Spin-off from #907760: EntityFieldQuery tests cleanup.
We have three ordering methods: propertyOrder, entityOrder, fieldOrder.
The problem shows itself when using more than one method.

The orderings are not added to the SelectQuery in the order in which they are defined, which leads to unexpected behaviour.
It can't be the same if I order by a field first, and then by a property second, and the other way around.
We need to fix entity.inc and field_sql_storage. Already discussed it with chx and should have a patch ready in the next 48h.

CommentFileSizeAuthor
#12 908798.patch13.83 KBbojanz
#8 908798.patch12.93 KBbojanz
#6 908798.patch12.94 KBbojanz
#5 908798.patch12.93 KBbojanz
#2 908798.patch10.74 KBbojanz

Comments

chx’s picture

We need to yank entityOrder, fieldOrder, propertyOrder and add one order, it will be a list of ('type' => $type, 'specifier' => something, direction' => ASC) where $type can be entity, property, field and specifier will be the respective name / for field a list of the field and the column name. We need to keep a fieldIndex going. The fields array will become sparse (ie it wontbe indexed from 0...count-1 but it will 0,1 , 5, 9 as it needs to be the same index as the order array which contains nonfield things) but who cares?

bojanz’s picture

Status: Active » Needs review
StatusFileSize
new10.74 KB

Finally found some Drupal time.

Here's a patch. I want to add some more tests, but functionality wise it is done.

bojanz’s picture

+    // Ensure the same index is used for fields as for the order.

This is no longer valid, and will be replaced on reroll with "Save the index used for the new field, for later use in field storage".

chx’s picture

Status: Needs review » Needs work

I know + foreach ($this->propertyConditions as $entity_condition) { is from HEAD but care to fix it? it reads really WTFish. You can change + $index = $specifier['index']; $table_alias = $table_aliases[$index]; into just $table_alias = $table_aliases[$specifier['index']]. thanks for the great work. Are you sure there is no need for new tests?

bojanz’s picture

Status: Needs work » Needs review
StatusFileSize
new12.93 KB

Fixed.

And of course there's a need for new tests :) I said in #2 "I want to add some more tests". So yay, tests!

I added two more tests. We now have the following test combinations for multiple orderings:
1) propertyOrder + entityOrder in propertyQuery
2) propertyOrder + entityOrder in field storage
3) entityOrder + fieldOrder in field storage

I think this is enough. I can always add a fourth combination, propertyOrder + fieldOrder, but I think it's enough that all three variants are tested in a multiple-order scenario.

bojanz’s picture

StatusFileSize
new12.94 KB

Forgot ending dots in a few test descriptions.

This should be the last one.

chx’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

This is quite a find and quite a fix. We are getting closer to tablesort. A lot closer because we can ask the users to give us tablesort arrays in the form order stores them (almost).

bojanz’s picture

StatusFileSize
new12.93 KB

Oops, had a coding standard violation. Let's pretend that never happened.
Replaced two "else if" occurrences with "elseif".

Still RTBC.

chx’s picture

Note that once this is committed we have #885014: Add pager and tablesort to EntityFieldQuery ready too.

sun’s picture

+++ includes/entity.inc
@@ -1023,16 +1009,21 @@ class EntityFieldQuery {
+    ¶
...
+    ¶

+++ modules/field/modules/field_sql_storage/field_sql_storage.module
@@ -538,35 +538,53 @@ function field_sql_storage_field_storage_query(EntityFieldQuery $query) {
+  ¶
...
+  ¶
...
+  ¶

+++ modules/simpletest/tests/entity_query.test
@@ -416,30 +416,59 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
+    ¶

Trailing white-space here.

Powered by Dreditor.

dries’s picture

Status: Reviewed & tested by the community » Needs work

Let's get that fixed quickly then. :)

bojanz’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new13.83 KB

Fixed.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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