mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Associations documentatiion
This commit is contained in:
1 parent
f2b46963bd
commit
003020dd29
2 files changed
+23
-2
No files matched your search
@@ -1006,6 +1006,15 @@ let request = Book.aliased(bookAlias)
|
||||
.filter(sql: "myBook.publishDate >= myAuthor.deathDate")
|
||||
```
|
||||
|
||||
> :point_up: **Note**: avoid reusing table aliases between several tables or requests, because you will get a fatal error:
|
||||
>
|
||||
> ```swift
|
||||
> // Fatal error: A TableAlias most not be used to refer to multiple tables
|
||||
> let alias = TableAlias()
|
||||
> let books = Book.aliased(alias)...
|
||||
> let people = Person.aliased(alias)...
|
||||
> ```
|
||||
|
||||
|
||||
Fetching Values from Associations
|
||||
=================================
|
||||
|
||||
@@ -204,10 +204,16 @@ public class TableAlias: Hashable {
|
||||
case .undefined(let userName):
|
||||
self.impl = .table(tableName: tableName, userName: userName)
|
||||
case .table(tableName: let initialTableName, userName: _):
|
||||
// It is a programmer error to reuse the same TableAlias for
|
||||
// multiple tables.
|
||||
//
|
||||
// // Don't do that
|
||||
// let alias = TableAlias()
|
||||
// let books = Book.aliased(alias)...
|
||||
// let authors = Author.aliased(alias)...
|
||||
GRDBPrecondition(
|
||||
tableName.lowercased() == initialTableName.lowercased(),
|
||||
// Likely a GRDB bug
|
||||
"Can't change table name of a table alias")
|
||||
"A TableAlias most not be used to refer to multiple tables")
|
||||
case .proxy(let base):
|
||||
base.setTableName(tableName)
|
||||
}
|
||||
@@ -241,6 +247,12 @@ extension Array where Element == TableAlias {
|
||||
fileprivate var resolvedNames: [TableAlias: String] {
|
||||
// It is a programmer error to reuse the same TableAlias for
|
||||
// multiple tables.
|
||||
//
|
||||
// // Don't do that
|
||||
// let alias = TableAlias()
|
||||
// let request = Book
|
||||
// .including(required: Book.author.aliased(alias)...)
|
||||
// .including(required: Book.author.aliased(alias)...)
|
||||
GRDBPrecondition(count == Set(self).count, "A TableAlias most not be used to refer to multiple tables")
|
||||
|
||||
let groups = Dictionary(grouping: self) {
|
||||
|
||||
Reference in new issue
Block a user