mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
34 lines
1.0 KiB
Swift
34 lines
1.0 KiB
Swift
public struct HasManyThroughAssociation<Origin, Destination>: Association {
|
|
/// :nodoc:
|
|
public typealias OriginRowDecoder = Origin
|
|
|
|
/// :nodoc:
|
|
public typealias RowDecoder = Destination
|
|
|
|
/// :nodoc:
|
|
public var sqlAssociation: SQLAssociation
|
|
|
|
/// :nodoc:
|
|
public init(sqlAssociation: SQLAssociation) {
|
|
self.sqlAssociation = sqlAssociation
|
|
}
|
|
}
|
|
|
|
// Allow HasManyThroughAssociation(...).filter(key: ...)
|
|
extension HasManyThroughAssociation: TableRequest where Destination: TableRecord { }
|
|
|
|
extension TableRecord {
|
|
public static func hasMany<Pivot, Target>(
|
|
_ destination: Target.RowDecoder.Type,
|
|
through pivot: Pivot,
|
|
using target: Target)
|
|
-> HasManyThroughAssociation<Self, Target.RowDecoder>
|
|
where Pivot: Association,
|
|
Target: Association,
|
|
Pivot.OriginRowDecoder == Self,
|
|
Pivot.RowDecoder == Target.OriginRowDecoder
|
|
{
|
|
return HasManyThroughAssociation(sqlAssociation: target.sqlAssociation.appending(pivot.sqlAssociation))
|
|
}
|
|
}
|