loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

fix(sequelize): support ordering by associations

Open KalleV opened this issue 1 year ago • 1 comments

Support ordering by associations using this Sequelize API: https://sequelize.org/docs/v6/advanced-association-concepts/eager-loading

Fixes: #10374

Example:

{
  include: [
    {
      "relation": user
    }
  ],
  order: "user email ASC"
}
SQL generated by the test cases
sequelize:sql:sqlite Executing (default): SELECT `TodoList`.`id`, `TodoList`.`title`, `TodoList`.`user`, `todos`.`id` AS `todos.id`, `todos`.`title` AS `todos.title`, `todos`.`is_complete` AS `todos.isComplete`, `todos`.`todo_list_id` AS `todos.todoListId` FROM `TodoList` AS `TodoList` LEFT OUTER JOIN `Todo` AS `todos` ON `TodoList`.`id` = `todos`.`todo_list_id` ORDER BY `TodoList`.`title` DESC;

  sequelize:sql:sqlite Executed (default): SELECT `TodoList`.`id`, `TodoList`.`title`, `TodoList`.`user`, `todos`.`id` AS `todos.id`, `todos`.`title` AS `todos.title`, `todos`.`is_complete` AS `todos.isComplete`, `todos`.`todo_list_id` AS `todos.todoListId` FROM `TodoList` AS `TodoList` LEFT OUTER JOIN `Todo` AS `todos` ON `TodoList`.`id` = `todos`.`todo_list_id` ORDER BY `TodoList`.`title` DESC;
  
  sequelize:sql:sqlite Executing (default): SELECT `TodoList`.`id`, `TodoList`.`title`, `TodoList`.`user`, `todos`.`id` AS `todos.id`, `todos`.`title` AS `todos.title`, `todos`.`is_complete` AS `todos.isComplete`, `todos`.`todo_list_id` AS `todos.todoListId` FROM `TodoList` AS `TodoList` LEFT OUTER JOIN `Todo` AS `todos` ON `TodoList`.`id` = `todos`.`todo_list_id` ORDER BY `todos`.`title` DESC;
  
  sequelize:sql:sqlite Executed (default): SELECT `TodoList`.`id`, `TodoList`.`title`, `TodoList`.`user`, `todos`.`id` AS `todos.id`, `todos`.`title` AS `todos.title`, `todos`.`is_complete` AS `todos.isComplete`, `todos`.`todo_list_id` AS `todos.todoListId` FROM `TodoList` AS `TodoList` LEFT OUTER JOIN `Todo` AS `todos` ON `TodoList`.`id` = `todos`.`todo_list_id` ORDER BY `todos`.`title` DESC;

Checklist

  • [x] DCO (Developer Certificate of Origin) signed in all commits
  • [x] npm test passes on your machine
  • [x] New tests added or existing tests modified to cover all changes
  • [ ] Code conforms with the style guide
  • [ ] API Documentation in code was updated
  • [ ] Documentation in /docs/site was updated
  • [ ] Affected artifact templates in packages/cli were updated
  • [ ] Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

KalleV avatar Feb 16 '24 23:02 KalleV

Pull Request Test Coverage Report for Build 7937556855

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall first build on KalleV_support_relation_order_by at 55.371%

Totals Coverage Status
Change from base Build 7936815208: 55.4%
Covered Lines: 9563
Relevant Lines: 12457

💛 - Coveralls

coveralls avatar Feb 16 '24 23:02 coveralls