如何在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.*
的方法。
除了手动使用.simpleQuery(_:)
之外,是否可以在当前版本的蒸汽中执行此操作?
ENV:
蒸气:3.0.0.rc-2.7
流利:3.0.0.rc-2.3.3
Fluent-mysql:3.0.0.rc-2.3