diff --git a/tests/php/ORM/DataQueryTest.php b/tests/php/ORM/DataQueryTest.php index 0c8a6bf41..82e8ef3a0 100644 --- a/tests/php/ORM/DataQueryTest.php +++ b/tests/php/ORM/DataQueryTest.php @@ -24,6 +24,8 @@ class DataQueryTest extends SapphireTest DataQueryTest\ObjectE::class, DataQueryTest\ObjectF::class, DataQueryTest\ObjectG::class, + DataQueryTest\ObjectH::class, + DataQueryTest\ObjectI::class, SQLSelectTest\TestObject::class, SQLSelectTest\TestBase::class, SQLSelectTest\TestChild::class, @@ -405,4 +407,25 @@ class DataQueryTest extends SapphireTest $this->assertEquals('Last', $second['Title']); $this->assertEmpty(array_shift($arrayResult)); } + + /** + * Tests that sorting against multiple relationships is working + */ + public function testMultipleRelationSort() + { + $query = new DataQuery(DataQueryTest\ObjectH::class); + $query->applyRelation('ManyTestEs'); + $query->applyRelation('ManyTestIs'); + $query->sort([ + '"manytestes_DataQueryTest_E"."SortOrder"', + '"manytestis_DataQueryTest_I"."SortOrder"', + '"SortOrder"', + ]); + + $titles = $query->column('Name'); + + $this->assertEquals('First', $titles[0]); + $this->assertEquals('Second', $titles[1]); + $this->assertEquals('Last', $titles[2]); + } } diff --git a/tests/php/ORM/DataQueryTest.yml b/tests/php/ORM/DataQueryTest.yml index cb514c76a..917175cc2 100644 --- a/tests/php/ORM/DataQueryTest.yml +++ b/tests/php/ORM/DataQueryTest.yml @@ -8,3 +8,31 @@ SilverStripe\ORM\Tests\DataQueryTest\ObjectE: query3: Title: 'Second' SortOrder: 2 + +SilverStripe\ORM\Tests\DataQueryTest\ObjectI: + query1: + Title: 'First' + SortOrder: 1 + query2: + Title: 'Second' + SortOrder: 2 + query3: + Title: 'Last' + SortOrder: 3 + +SilverStripe\ORM\Tests\DataQueryTest\ObjectH: + query1: + Name: 'First' + SortOrder: 3 + ManyTestEs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectE.query2 + ManyTestIs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectI.query2 + query2: + Name: 'Last' + SortOrder: 1 + ManyTestEs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectE.query1 + ManyTestIs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectI.query1 + query3: + Name: 'Second' + SortOrder: 2 + ManyTestEs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectE.query2 + ManyTestIs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectI.query3 diff --git a/tests/php/ORM/DataQueryTest/ObjectH.php b/tests/php/ORM/DataQueryTest/ObjectH.php new file mode 100644 index 000000000..1e28d80f7 --- /dev/null +++ b/tests/php/ORM/DataQueryTest/ObjectH.php @@ -0,0 +1,21 @@ + 'Varchar', + 'SortOrder' => 'Int', + ); + + private static $many_many = array( + 'ManyTestEs' => ObjectE::class, + 'ManyTestIs' => ObjectI::class, + ); +} diff --git a/tests/php/ORM/DataQueryTest/ObjectI.php b/tests/php/ORM/DataQueryTest/ObjectI.php new file mode 100644 index 000000000..03f535667 --- /dev/null +++ b/tests/php/ORM/DataQueryTest/ObjectI.php @@ -0,0 +1,16 @@ + 'Varchar', + 'SortOrder' => 'Int', + ); +}