-
Couldn't load subscription status.
- Fork 8
Ordering by a selection result dto field (functional sorting)
gert-wijns edited this page Sep 13, 2014
·
2 revisions
To sort the results using one of the result dto properties, use query.orderBy().desc(dto.getProperty()). It makes more sense to sort this way because the goal is to sort the result (on database level). As an added benefit, it becomes easier to write code which allows sorting without having to know the details of the query.
Person person = query.from(Person.class);
PersonDto dto = query.select(PersonDto.class);
dto.setThePersonsName(person.getName());
query.orderBy().desc(dto.getThePersonsName());
=> "select hobj1.name as thePersonsName
from Person hobj1
order by hobj1.name desc"