Skip to content

Relationship

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

Relationship

A protocol representing a relationship between two Models. Contains only those two types and functionality for eager loading this relationship.

public protocol Relationship

Requirements

loadRelationships(for:​query:​into:​)

Given an array of Froms, this function loads objects from the relationship eagerLoadKeyPath and sets them on each From.

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

Parameters

  • from: The array of From to eager load a relationship on.
  • nestedQuery: A closure for generating the query to find the related To objects.
  • eagerLoadKeyPath: The KeyPath of the relationship. Once loaded, the To objects will be set here.

Returns

A future containing the From models, with the relationships at the eagerLoadKeyPath populated & ready for access.

Alchemy
Types
Protocols
Global Typealiases
Global Variables
Global Functions
Fusion
Types
Protocols
Papyrus
Types
Protocols
Clone this wiki locally