Skip to content

Sort collection resource by associated property [DATAREST-1280] #1641

Open
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions