Skip to content

HasManyRelationship

Josh Wright edited this page Jan 14, 2021 · 4 revisions

HasManyRelationship

Either side of a M - M relationship or the parent of a 1 - M relationship. The details of this relationship are defined in the initializers inherited from HasRelationship.

@propertyWrapper public final class HasManyRelationship<From: Model, To: ModelMaybeOptional>: HasRelationship<From, To>, Encodable, Relationship

Inheritance

Encodable, HasRelationship<From, To>, Relationship

Initializers

init(propertyName:to:keyString:)

public required init(propertyName: String? = nil, to key: KeyPath<To.Value, To.Value.BelongsTo<From>>, keyString: String = To.Value.keyMappingStrategy.map(input: "\(From.self)Id"))

init(propertyName:from:to:fromString:toString:)

public required init<Through: Model>(propertyName: String? = nil, from fromKey: KeyPath<Through, Through.BelongsTo<From.Value>>, to toKey: KeyPath<Through, Through.BelongsTo<To.Value>>, fromString: String = Through.keyMappingStrategy.map(input: "\(From.self)Id"), toString: String = Through.keyMappingStrategy.map(input: "\(To.Value.self)Id"))

init(from:)

public required init(from decoder: Decoder) throws

Properties

wrappedValue

The related [Model] object. Accessing this will fatalError if the relationship is not already loaded via eager loading or set manually.

var wrappedValue: [To]

projectedValue

The projected value of this property wrapper is itself. Used for when a reference to the relationship type is needed, such as during eager loads.

var projectedValue: From.HasMany<To>

Methods

loadRelationships(for:query:into:)

public func loadRelationships(for from: [From], query nestedQuery: @escaping (ModelQuery<To.Value>) -> ModelQuery<To.Value>, into eagerLoadKeyPath: KeyPath<From, From.HasMany<To>>) -> EventLoopFuture<[From]>

encode(to:)

public func encode(to encoder: Encoder) throws
Alchemy
Types
Protocols
Global Typealiases
Global Variables
Global Functions
Fusion
Types
Protocols
Papyrus
Types
Protocols
Clone this wiki locally