-
Notifications
You must be signed in to change notification settings - Fork 14
BelongsToRelationship
The child of a 1 - M or a 1 - 1 relationship. Backed by an
identifier of the parent, when encoded to a database, this
type attempt to write that identifier to a column named
<property-name>_id
.
@propertyWrapper public final class BelongsToRelationship<Child: Model, Parent: ModelMaybeOptional>: AnyBelongsTo, Codable, Relationship
Example:
struct Pet: Model {
static let table = "pets"
...
@BelongsTo
var owner: User // The ID value of this User will be stored
// under the `owner_id` column in the
// `pets` table.
}
AnyBelongsTo
, Codable
, ExpressibleByNilLiteral
, Relationship
public typealias From = Child
public typealias To = Parent
Initialize this relationship with an Identifier
of the
Parent
type.
public init(_ parentID: Parent.Value.Identifier)
- parentID: the identifier of the
Parent
to which this child belongs.
Initialize this relationship with an instance of Parent
.
public init(_ parent: Parent.Value)
- parent: The
Parent
object to which this child belongs.
public init(from decoder: Decoder) throws
The identifier of this relationship's parent.
var id: Parent.Value.Identifier!
The related Model
object. Accessing this will fatalError
if the relationship is not already loaded via eager loading
or set manually.
var wrappedValue: Parent
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: Child.BelongsTo<Parent>
public func loadRelationships(for from: [Child], query nestedQuery: @escaping (ModelQuery<Parent.Value>) -> ModelQuery<Parent.Value>, into eagerLoadKeyPath: KeyPath<Child, Child.BelongsTo<Parent>>) -> EventLoopFuture<[Child]>
public func encode(to encoder: Encoder) 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