Skip to content

HasOneRelationship

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

HasOneRelationship

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

@propertyWrapper public final class HasOneRelationship<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

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: HasOneRelationship<From, To>

wrappedValue

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

var wrappedValue: 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.HasOne<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