Skip to content

HasRelationship

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

HasRelationship

Contains shared behavior for "has" relationships, particularly around eager loading functionality.

public class HasRelationship<From: Model, To: ModelMaybeOptional>: AnyHas, Decodable

Inheritance

AnyHas, Decodable

Initializers

init(propertyName:to:keyString:)

Initializes this relationship as a 1 - M. This assumes that there is a key on the To table that has a reference to From.id.

public required init(propertyName: String? = nil, to key: KeyPath<To.Value, To.Value.BelongsTo<From>>, keyString: String)

Parameters

  • this: The name of this property. The name must be unique on a From / To type basis. i.e. for each relationship to To on type From, there must be a unique name. This is an implementation detail leaking out, sorry another way hasn't been found.
  • key: The KeyPath of the relationship on To that points to From.
  • keyString: The string name of the column on To that points to From's id.

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

Initializes this relationship as a M - M. This assumes that there is a pivot table with columns representing the primary keys of both From and To.

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, toString: String)

Parameters

  • named: A unique name for this. The name must be unique on a From / To type basis. i.e. for each relationship to To on type From, there must be a unique name. This is an implementation detail leaking out, sorry another way hasn't been found.
  • fromKey: The KeyPath on the pivot table that points to the From type in the relationship.
  • toKey: The KeyPath on the pivot table that points to the To type in the relationship.
  • fromString: The column name on the pivot table that references the From table's id.
  • toString: The column name on the pivot table that references the To table's id.

init(from:)

public required init(from decoder: Decoder) throws
Alchemy
Types
Protocols
Global Typealiases
Global Variables
Global Functions
Fusion
Types
Protocols
Papyrus
Types
Protocols
Clone this wiki locally