Improve sample code

This commit is contained in:
Gwendal Roué committed 2018-10-05 18:50:34 +02:00
1 parent 7508811e40
commit 047a95f2c9
1 file changed
+2 -2
+2 -2
View File
@@ -1514,7 +1514,7 @@ You can compute aggregates on subsets of associated records with the `filter` me
```swift
struct AuthorInfo: Decodable, FetchableRecord {
var author: Author
var bookCount: Int
var novelCount: Int
}
// SELECT author.*,
@@ -1523,7 +1523,7 @@ struct AuthorInfo: Decodable, FetchableRecord {
// LEFT JOIN book ON book.authorId = author.id AND book.kind = 'novel'
// GROUP BY author.id
let novels = Author.books.filter(Column("kind") == "novel")
let request = Author.annotated(with: novels.count())
let request = Author.annotated(with: novels.count(aliased: "novelCount"))
let authorInfos: [AuthorInfo] = try AuthorInfo.fetchAll(db, request)
```