HasRelationships

 trait Winter\Storm\Database\Concerns\HasRelationships

Properties

public $attachMany : mixed

protected $attachMany = [ 'pictures' => ['Winter\Storm\Database\Attach\File', 'name'=> 'imageable'] ];

public $attachOne : mixed

protected $attachOne = [ 'picture' => ['Winter\Storm\Database\Attach\File', 'public' => false] ];

public $belongsTo : mixed

protected $belongsTo = [ 'parent' => ['Category', 'key' => 'parent_id'] ];

public $belongsToMany : mixed

protected $belongsToMany = [ 'groups' => ['Group', 'table'=> 'join_groups_users'] ];

public $hasMany : array

Cleaner declaration of relationships.

Uses a similar approach to the relation methods used by Eloquent, but as separate properties that make the class file less cluttered.

It should be declared with keys as the relation name, and value being a mixed array. The relation type $morphTo does not include a classname as the first value.

Example: class Order extends Model { protected $hasMany = [ 'items' => 'Item' ]; }

public $hasManyThrough : mixed

protected $hasManyThrough = [ 'posts' => ['Posts', 'through' => 'User'] ];

public $hasOne : mixed

protected $hasOne = [ 'owner' => ['User', 'key' => 'user_id'] ];

public $hasOneThrough : mixed

protected $hasOneThrough = [ 'post' => ['Posts', 'through' => 'User'] ];

public $morphMany : mixed

protected $morphMany = [ 'log' => ['History', 'name' => 'user'] ];

public $morphOne : mixed

protected $morphOne = [ 'log' => ['History', 'name' => 'user'] ];

public $morphTo : mixed

protected $morphTo = [ 'pictures' => [] ];

public $morphToMany : mixed

protected $morphToMany = [ 'tag' => ['Tag', 'table' => 'tagables', 'name' => 'tagable'] ];

public $morphedByMany : mixed

protected static $relationTypes : array

Excepted relationship types, used to cycle and verify relationships.

Methods

public addAttachManyRelation (string $name, array $config) : void

Dynamically add an AttachMany relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addAttachOneRelation (string $name, array $config) : void

Dynamically add an AttachOne relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addBelongsToManyRelation (string $name, array $config) : void

Dynamically add a BelongsToMany relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addBelongsToRelation (string $name, array $config) : void

Dynamically add a BelongsTo relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addHasManyRelation (string $name, array $config) : void

Dynamically add a HasMany relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addHasManyThroughRelation (string $name, array $config) : void

Dynamically add a(n) HasManyThrough relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addHasOneRelation (string $name, array $config) : void

Dynamically add a HasOne relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addHasOneThroughRelation (string $name, array $config) : void

Dynamically add a(n) HasOneThrough relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addMorphManyRelation (string $name, array $config) : void

Dynamically add a MorphMany relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addMorphOneRelation (string $name, array $config) : void

Dynamically add a MorphOne relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addMorphToManyRelation (string $name, array $config) : void

Dynamically add a MorphToMany relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addMorphToRelation (string $name, array $config) : void

Dynamically add a MorphTo relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public addMorphedByManyRelation (string $name, array $config) : void

Dynamically add a MorphedByMany relationship

Parameters
Property Description
$name
string
$config
array
Returns
void

public attachMany ($related, $isPublic = null, $localKey = null, $relationName = null) : Winter\Storm\Database\Relations\AttachMany

Define an attachment one-to-many relationship.

This code is a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$isPublic
mixed
$localKey
mixed
$relationName
mixed
Returns

public attachOne ($related, boolean $isPublic = true, $localKey = null, $relationName = null) : Winter\Storm\Database\Relations\AttachOne

Define an attachment one-to-one relationship.

This code is a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$isPublic
boolean
$localKey
mixed
$relationName
mixed
Returns

public belongsTo ($related, $foreignKey = null, $parentKey = null, $relationName = null) : Winter\Storm\Database\Relations\BelongsTo

Define an inverse one-to-one or many relationship.

Overridden from {@link Eloquent\Model} to allow the usage of the intermediary methods to handle the {@link $relationsData} array.

Parameters
Property Description
$related
mixed
$foreignKey
mixed
$parentKey
mixed
$relationName
mixed
Returns

public belongsToMany ($related, $table = null, $primaryKey = null, $foreignKey = null, $parentKey = null, $relatedKey = null, $relationName = null) : Winter\Storm\Database\Relations\BelongsToMany

Define a many-to-many relationship.

This code is almost a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$table
mixed
$primaryKey
mixed
$foreignKey
mixed
$parentKey
mixed
$relatedKey
mixed
$relationName
mixed
Returns

public getRelationDefinition (string $name) : array | null

Returns relationship details from a supplied name.

Parameters
Property Description
$name
string

Relation name

Returns
array | null

public getRelationDefinitions () : array

Returns relationship details for all relations defined on this model.

Returns
array

public getRelationType (string $name) : string | null

Returns a relationship type based on a supplied name.

Parameters
Property Description
$name
string
Returns
string | null

public getRelationTypeDefinition (string $type, string $name) : string | null

Returns the given relation definition.

Parameters
Property Description
$type
string

Relation type

$name
string

Relation name

Returns
string | null

public getRelationTypeDefinitions (string $type) : array | string | null

Returns all defined relations of given type.

Parameters
Property Description
$type
string

Relation type

Returns
array | string | null

public getRelationValue ($relationName)

Returns a relation key value(s), not as an object.

Parameters
Property Description
$relationName
mixed
Returns
mixed

public hasMany ($related, $primaryKey = null, $localKey = null, $relationName = null) : Winter\Storm\Database\Relations\HasMany

Define a one-to-many relationship.

This code is a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$primaryKey
mixed
$localKey
mixed
$relationName
mixed
Returns

public hasManyThrough ($related, $through, $primaryKey = null, $throughKey = null, $localKey = null, $secondLocalKey = null, $relationName = null) : Winter\Storm\Database\Relations\HasManyThrough

Define a has-many-through relationship.

This code is a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$through
mixed
$primaryKey
mixed
$throughKey
mixed
$localKey
mixed
$secondLocalKey
mixed
$relationName
mixed
Returns

public hasOne ($related, $primaryKey = null, $localKey = null, $relationName = null) : Winter\Storm\Database\Relations\HasOne

Define a one-to-one relationship.

This code is a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$primaryKey
mixed
$localKey
mixed
$relationName
mixed
Returns

public hasOneThrough ($related, $through, $primaryKey = null, $throughKey = null, $localKey = null, $secondLocalKey = null, $relationName = null) : Winter\Storm\Database\Relations\HasOneThrough

Define a has-one-through relationship.

This code is a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$through
mixed
$primaryKey
mixed
$throughKey
mixed
$localKey
mixed
$secondLocalKey
mixed
$relationName
mixed
Returns

public hasRelation (string $name) : bool

Checks if model has a relationship by supplied name.

Parameters
Property Description
$name
string

Relation name

Returns
bool

public isRelationPushable (string $name) : bool

Determines whether the specified relation should be saved when push() is called instead of save() on the model. Default: true.

Parameters
Property Description
$name
string

Relation name

Returns
bool

public makeRelation (string $name) : Winter\Storm\Database\Model | null

Returns a new instance of a related model

Parameters
Property Description
$name
string
Returns
Winter\Storm\Database\Model | null

public morphMany ($related, $name, $type = null, $id = null, $localKey = null, $relationName = null) : Winter\Storm\Database\Relations\MorphMany

Define a polymorphic one-to-many relationship.

This code is a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$name
mixed
$type
mixed
$id
mixed
$localKey
mixed
$relationName
mixed
Returns

public morphOne ($related, $name, $type = null, $id = null, $localKey = null, $relationName = null) : Winter\Storm\Database\Relations\MorphOne

Define a polymorphic one-to-one relationship.

This code is a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$name
mixed
$type
mixed
$id
mixed
$localKey
mixed
$relationName
mixed
Returns

public morphTo ($name = null, $type = null, $id = null, $ownerKey = null) : Winter\Storm\Database\Relations\MorphTo

Define an polymorphic, inverse one-to-one or many relationship.

Overridden from {@link Eloquent\Model} to allow the usage of the intermediary methods to handle the relation.

Parameters
Property Description
$name
mixed
$type
mixed
$id
mixed
$ownerKey
mixed
Returns

public morphToMany ($related, $name, $table = null, $primaryKey = null, $foreignKey = null, $parentKey = null, $relatedKey = null, boolean $inverse = false, $relationName = null) : Winter\Storm\Database\Relations\MorphToMany

Define a polymorphic many-to-many relationship.

This code is almost a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$name
mixed
$table
mixed
$primaryKey
mixed
$foreignKey
mixed
$parentKey
mixed
$relatedKey
mixed
$inverse
boolean
$relationName
mixed
Returns

public morphedByMany ($related, $name, $table = null, $primaryKey = null, $foreignKey = null, $parentKey = null, $relatedKey = null, $relationName = null) : Winter\Storm\Database\Relations\MorphToMany

Define a polymorphic many-to-many inverse relationship.

This code is almost a duplicate of Eloquent but uses a Storm relation class.

Parameters
Property Description
$related
mixed
$name
mixed
$table
mixed
$primaryKey
mixed
$foreignKey
mixed
$parentKey
mixed
$relatedKey
mixed
$relationName
mixed
Returns

protected addRelation (string $type, string $name, array $config) : void

Dynamically add the provided relationship configuration to the local properties

Parameters
Property Description
$type
string
$name
string
$config
array
Returns
void

protected getMorphs (string $name, string | null $type = null, string | null $id = null) : array

Get the polymorphic relationship columns.

Parameters
Property Description
$name
string
$type
string | null
$id
string | null
Returns
array

protected getRelationCaller ()

Finds the calling function name from the stack trace.

Returns
mixed

protected getRelationDefaults (string $type) : array

Returns default relation arguments for a given type.

Parameters
Property Description
$type
string

Relation type

Returns
array

protected handleRelation (string $relationName) : Illuminate\Database\Eloquent\Relations\Relation

Looks for the relation and does the correct magic as Eloquent would require inside relation methods. For more information, read the documentation of the mentioned property.

Parameters
Property Description
$relationName
string

the relation key, camel-case version

Returns
Illuminate\Database\Eloquent\Relations\Relation

protected morphEagerTo (string $name, string $type, string $id, string $ownerKey) : Winter\Storm\Database\Relations\MorphTo

Define a polymorphic, inverse one-to-one or many relationship.

Parameters
Property Description
$name
string
$type
string
$id
string
$ownerKey
string
Returns

protected morphInstanceTo (string $target, string $name, string $type, string $id, string | null $ownerKey = null) : Winter\Storm\Database\Relations\MorphTo

Define a polymorphic, inverse one-to-one or many relationship.

Parameters
Property Description
$target
string
$name
string
$type
string
$id
string
$ownerKey
string | null
Returns

protected setRelationValue ($relationName, $value)

Sets a relation value directly from its attribute.

Parameters
Property Description
$relationName
mixed
$value
mixed
Returns
mixed

protected validateRelationArgs ($relationName, $optional, array $required = [])

Validate relation supplied arguments.

Parameters
Property Description
$relationName
mixed
$optional
mixed
$required
array
Returns
mixed

Used by

Class Description
File

File attachment model

Parameter

Parameters model Used for storing internal application parameters.

Revision

Revision history model

User

Administrator user model

UserGroup

Administrator group

UserPreference

All preferences for the backend user

UserRole

Administrator role

UserThrottle

Administrator throttling model

Group

Group model

Preferences

User Preferences model

Role

Role model

Throttle

Throttle model

User

User model

File

File attachment model

Model

Active Record base class.

DeferredBinding

Deferred Binding Model

Revision

Revision Model

MorphPivot

Reimplementation of \Illuminate\Database\Eloquent\Relations\MorphPivot but extends Winter's Pivot base class instead of Laravel's to get access to Winter magic.

Pivot
Copyright © 2024 Winter CMS