如何在fluentvapor3中按动态列排序

pdsfdshx  于 2021-06-24  发布在  Mysql
关注(0)|答案(0)|浏览(318)

如何在fluent中执行这样的sql查询?

SELECT `book`.*
  FROM `book`
  JOIN `book_user` ON `book`.`id` = `book_user`.`bookId`
GROUP BY `book`.`id`
ORDER BY COUNT(`book`.`id`) DESC;

我试图通过以下方法实现这一点:

Book.query(on: req)
    .join(UserBookPivot.self, field: \UserBookPivot.bookId, to: \Book.id, method: .inner)
    .group(by: \Book.id)
    .sort(\Book.id, .descending)
    .all()

只产生了这样一个查询:

SELECT * 
--     ^
  FROM `book` 
  JOIN `book_user` ON `book`.`id` = `book_user`.`bookId` 
GROUP BY `book`.`id` 
ORDER BY `book`.`id` DESC;
--       ^^^^^^^^^^^

还是找不到办法生产 ORDER BY COUNT(book.id) 以及 SELECT book.* .
在当前版本的vapor中,除了使用 .simpleQuery(_:) 手动?
环境:
蒸汽:3.0.0.rc-2.7
流利:3.0.0.rc-2.3.3
fluent-mysql:3.0.0.rc-2.3

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题