spring-projects / spring-projects/spring-data-rest
Sort collection resource by associated property [DATAREST-1280]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
cptwunderlich opened DATAREST-1280 and commented
Collection resources can't be sorted by associated properties.
This is a huge and quite franky not very understandable limitation.
I have prepared an example - link can be found in "Reference URL".
The example uses Articles having a Unit. Querying via JPQL like in the Unit Test works like a charm. Just passing "unit.code" works and since that is the primary key, no join is needed. Adding "unit.fullName" to the query automatically uses a join, without changing the query.
I've also added QueryDsl to the Example, to show how strange it seems, that you can filter by a property, but you can't sort by it.
Where this is really stands out is with Projections/Excerpts. I want to list my Articles and I'd like to sort by Unit. Now I'm including the Unit's abbreviation or code in the Projection and knowing the property name, I can even filter it - but I just can't sort by it.
Digging through the framework, I found JacksonMappingAwareSortTranslator.mapPropertyPath(), which returns if it finds a linkable association, instead of continuing creating the 'sort' property. Why? What's the rationale?
Affects: 3.0.9 (Kay SR9)
Reference URL: https://github.com/cptwunderlich/SpringDataRestMWEs/tree/master/AssociationSort
2 votes, 3 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.