Skip to content

[DATAJDBC-530] The sorting property set as the property name. #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
* @author Tom Hombergs
* @author Tyler Van Gorder
* @author Milan Milanov
* @author Myeonghyeon Lee
*/
class SqlGenerator {

Expand Down Expand Up @@ -659,7 +660,13 @@ private String renderReference(SqlIdentifier identifier) {

private List<OrderByField> extractOrderByFields(Sort sort) {
return sort.stream()
.map(order -> OrderByField.from(Column.create(order.getProperty(), this.getTable()), order.getDirection()))
.map(order -> {
Column column = Column.create(
this.entity.getRequiredPersistentProperty(order.getProperty()).getColumnName(),
this.getTable()
);
return OrderByField.from(column, order.getDirection());
})
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* @author Mark Paluch
* @author Tom Hombergs
* @author Milan Milanov
* @author Myeonghyeon Lee
*/
public class SqlGeneratorUnitTests {

Expand Down Expand Up @@ -177,7 +178,7 @@ public void findAllSortedByUnsorted() {
@Test // DATAJDBC-101
public void findAllSortedBySingleField() {

String sql = sqlGenerator.getFindAll(Sort.by("x_name"));
String sql = sqlGenerator.getFindAll(Sort.by("name"));

assertThat(sql).contains("SELECT", //
"dummy_entity.id1 AS id1", //
Expand All @@ -197,7 +198,7 @@ public void findAllSortedBySingleField() {
public void findAllSortedByMultipleFields() {

String sql = sqlGenerator.getFindAll(
Sort.by(new Sort.Order(Sort.Direction.DESC, "x_name"), new Sort.Order(Sort.Direction.ASC, "x_other")));
Sort.by(new Sort.Order(Sort.Direction.DESC, "name"), new Sort.Order(Sort.Direction.ASC, "other")));

assertThat(sql).contains("SELECT", //
"dummy_entity.id1 AS id1", //
Expand Down Expand Up @@ -245,7 +246,7 @@ public void findAllPaged() {
@Test // DATAJDBC-101
public void findAllPagedAndSorted() {

String sql = sqlGenerator.getFindAll(PageRequest.of(3, 10, Sort.by("x_name")));
String sql = sqlGenerator.getFindAll(PageRequest.of(3, 10, Sort.by("name")));

assertThat(sql).contains("SELECT", //
"dummy_entity.id1 AS id1", //
Expand Down