-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #1392 Allow to sort using Doctrine associations (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #1392). Discussion ---------- Allow to sort using Doctrine associations This is a very early "proof of concept" to solve issues like #1337 which allow to sort entities using Doctrine associations. Example: ```yaml entities: Article: # ... sort: author.name ``` --- If we support this, my intention is to only support 1 nesting level (e.g. `author.name`) and not deeper nesting (e.g. `purchase.item.product.name`). **My question**: doing a naïve `$queryBuilder->join(...)` will work in all cases? Commits ------- bbe620c Allow to sort using Doctrine associations
- Loading branch information
Showing
8 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Tests/Configuration/fixtures/exceptions/sort.invalid_association_property.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# TEST | ||
# when 'sort' uses a Doctrine association (sort: author.name) the first part | ||
# (in this example, 'author') must refer to a valid entity property | ||
|
||
# EXCEPTION | ||
expected_exception: | ||
class: InvalidArgumentException | ||
message_string: 'The "this-does-not-exist" field used in the "sort" option of the "list" view of the "Category" entity does not exist neither as a property of that entity nor as a virtual field of that view.' | ||
|
||
# CONFIGURATION | ||
easy_admin: | ||
entities: | ||
Category: | ||
class: AppTestBundle\Entity\UnitTests\Category | ||
list: | ||
sort: 'this-does-not-exist.name' |
15 changes: 15 additions & 0 deletions
15
Tests/Configuration/fixtures/exceptions/sort_multiple_levels.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# TEST | ||
# the sort field can only contain up to one nesting level (e.g. aaa.bbb) | ||
|
||
# EXCEPTION | ||
expected_exception: | ||
class: InvalidArgumentException | ||
message_string: 'The "association1.association2.property" value cannot be used as the "sort" option in the "list" view of the "Category" entity because it defines multiple sorting levels (e.g. "aaa.bbb.ccc") but only up to one level is supported (e.g. "aaa.bbb").' | ||
|
||
# CONFIGURATION | ||
easy_admin: | ||
entities: | ||
Category: | ||
class: AppTestBundle\Entity\UnitTests\Category | ||
list: | ||
sort: 'association1.association2.property' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the EasyAdminBundle. | ||
* | ||
* (c) Javier Eguiluz <javier.eguiluz@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JavierEguiluz\Bundle\EasyAdminBundle\Tests\Controller; | ||
|
||
use JavierEguiluz\Bundle\EasyAdminBundle\Tests\Fixtures\AbstractTestCase; | ||
|
||
class EntitySortingByAssociationTest extends AbstractTestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->initClient(array('environment' => 'entity_sorting_by_association')); | ||
} | ||
|
||
public function testListViewSorting() | ||
{ | ||
$crawler = $this->requestListView(); | ||
|
||
$this->assertContains('sorted', $crawler->filter('th[data-property-name="parent"]')->attr('class')); | ||
$this->assertContains('fa-caret-down', $crawler->filter('th[data-property-name="parent"] i')->attr('class')); | ||
} | ||
|
||
public function testSearchViewSorting() | ||
{ | ||
$crawler = $this->requestSearchView(); | ||
|
||
$this->assertContains('sorted', $crawler->filter('th[data-property-name="parent"]')->attr('class')); | ||
$this->assertContains('fa-caret-up', $crawler->filter('th[data-property-name="parent"] i')->attr('class')); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Tests/Fixtures/App/config/config_entity_sorting_by_association.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
imports: | ||
- { resource: config.yml } | ||
|
||
easy_admin: | ||
entities: | ||
Category: | ||
class: AppTestBundle\Entity\FunctionalTests\Category | ||
list: | ||
sort: parent.name | ||
search: | ||
sort: [parent.name, ASC] |