-
Notifications
You must be signed in to change notification settings - Fork 14
HasRelationship
Josh Wright edited this page Jan 14, 2021
·
3 revisions
Contains shared behavior for "has" relationships, particularly around eager loading functionality.
public class HasRelationship<From: Model, To: ModelMaybeOptional>: AnyHas, Decodable
AnyHas
, Decodable
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)
- this: The name of this property. The name must be unique on a
From
/To
type basis. i.e. for each relationship toTo
on typeFrom
, 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 onTo
that points toFrom
. - keyString: The string name of the column on
To
that points toFrom
's id.
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)
- named: A unique name for this. The name must be unique on a
From
/To
type basis. i.e. for each relationship toTo
on typeFrom
, 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 theFrom
type in the relationship. - toKey: The
KeyPath
on the pivot table that points to theTo
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.
public required init(from decoder: Decoder) throws
Generated at 2021-01-13T22:24:59-0800 using swift-doc 1.0.0-beta.5.
Alchemy
Types
- AlterTableBuilder
- BCryptDigest
- BasicAuthMiddleware
- BcryptError
- BelongsToRelationship
- CORSMiddleware
- CORSMiddleware.AllowOriginSetting
- CORSMiddleware.Configuration
- ColumnType
- CreateColumn
- CreateColumnBuilder
- CreateIndex
- CreateTableBuilder
- DatabaseConfig
- DatabaseError
- DatabaseField
- DatabaseKeyMappingStrategy
- DatabaseValue
- DayUnit
- Env
- FrequencyTyped
- Grammar
- HTTPAuth
- HTTPAuth.Basic
- HTTPAuth.Bearer
- HTTPBody
- HTTPError
- HasManyRelationship
- HasOneRelationship
- HasRelationship
- HourUnit
- JoinClause
- JoinType
- Launch
- Log
- MIMEType
- MinuteUnit
- ModelQuery
- MySQLDatabase
- Operator
- OrderClause
- OrderClause.Sort
- OrderedDictionary
- PapyrusClientError
- PathParameter
- PathParameter.DecodingError
- PostgresDatabase
- Query
- Request
- Response
- Router
- RuneError
- SQL
- SQLJSON
- Scheduler
- Schema
- SecondUnit
- Services
- Socket
- StaticFileMiddleware
- StringLength
- Thread
- TokenAuthMiddleware
- WeekUnit
- Weekday
- WhereBoolean
- WhereColumn
- WhereIn
- WhereIn.InType
- WhereNested
- WhereRaw
- WhereValue