mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
SQLAssociation.associationForFirst()
This commit is contained in:
1 parent
4483f037a4
commit
6f125bd3d7
2 files changed
+6
-4
No files matched your search
@@ -103,10 +103,7 @@ public struct HasManyAssociation<Origin: TableRecord, Destination: TableRecord>:
|
||||
|
||||
/// TODO
|
||||
public var first: HasOneAssociation<Origin, Destination> {
|
||||
assert(sqlAssociation.steps.count == 1)
|
||||
var step = sqlAssociation.steps[0]
|
||||
step.firstOnly = true
|
||||
return HasOneAssociation(sqlAssociation: SQLAssociation(steps: [step]))
|
||||
HasOneAssociation(sqlAssociation: sqlAssociation.associationForFirst())
|
||||
}
|
||||
|
||||
/// TODO
|
||||
|
||||
@@ -97,6 +97,10 @@ public /* TODO: internal */ struct SQLAssociation {
|
||||
SQLAssociation(steps: other.steps + steps)
|
||||
}
|
||||
|
||||
func associationForFirst() -> Self {
|
||||
SQLAssociation(steps: steps.map { $0.with(\.firstOnly, true) })
|
||||
}
|
||||
|
||||
/// Given an origin alias and rows, returns the destination of the
|
||||
/// association as a relation.
|
||||
///
|
||||
@@ -204,6 +208,7 @@ struct SQLAssociationStep: Refinable {
|
||||
var key: SQLAssociationKey
|
||||
var condition: SQLAssociationCondition
|
||||
var relation: SQLRelation
|
||||
// TODO: I have problems understanding what cardinality=toMany + firstOnly=true mean.
|
||||
var cardinality: SQLAssociationCardinality
|
||||
var firstOnly: Bool
|
||||
|
||||
|
||||
Reference in new issue
Block a user