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
= ["hasOne","hasMany","belongsTo","belongsToMany","morphTo","morphOne","morphMany","morphToMany","morphedByMany","attachOne","attachMany","hasOneThrough","hasManyThrough"]
Excepted relationship types, used to cycle and verify relationships.
Methods
public addAttachManyRelation (string $name, array $config) : void
Dynamically add an AttachMany relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addAttachOneRelation (string $name, array $config) : void
Dynamically add an AttachOne relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addBelongsToManyRelation (string $name, array $config) : void
Dynamically add a BelongsToMany relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addBelongsToRelation (string $name, array $config) : void
Dynamically add a BelongsTo relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addHasManyRelation (string $name, array $config) : void
Dynamically add a HasMany relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addHasManyThroughRelation (string $name, array $config) : void
Dynamically add a(n) HasManyThrough relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addHasOneRelation (string $name, array $config) : void
Dynamically add a HasOne relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addHasOneThroughRelation (string $name, array $config) : void
Dynamically add a(n) HasOneThrough relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addMorphManyRelation (string $name, array $config) : void
Dynamically add a MorphMany relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addMorphOneRelation (string $name, array $config) : void
Dynamically add a MorphOne relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addMorphToManyRelation (string $name, array $config) : void
Dynamically add a MorphToMany relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addMorphToRelation (string $name, array $config) : void
Dynamically add a MorphTo relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
public addMorphedByManyRelation (string $name, array $config) : void
Dynamically add a MorphedByMany relationship
Property | Type | Description |
---|---|---|
$name | string |
string
|
$config | array |
array
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$isPublic | mixed |
mixed
|
$localKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$isPublic | boolean |
boolean
|
$localKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$foreignKey | mixed |
mixed
|
$parentKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$table | mixed |
mixed
|
$primaryKey | mixed |
mixed
|
$foreignKey | mixed |
mixed
|
$parentKey | mixed |
mixed
|
$relatedKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
public getRelationDefinition (string $name) : array | null
Returns relationship details from a supplied name.
Property | Type | Description |
---|---|---|
$name | string |
string
Relation name |
public getRelationDefinitions () : array
Returns relationship details for all relations defined on this model.
public getRelationType (string $name) : string | null
Returns a relationship type based on a supplied name.
Property | Type | Description |
---|---|---|
$name | string |
string
|
public getRelationTypeDefinition (string $type, string $name) : string | null
Returns the given relation definition.
Property | Type | Description |
---|---|---|
$type | string |
string
Relation type |
$name | string |
string
Relation name |
public getRelationTypeDefinitions (string $type) : array | string | null
Returns all defined relations of given type.
Property | Type | Description |
---|---|---|
$type | string |
string
Relation type |
public getRelationValue ($relationName)
Returns a relation key value(s), not as an object.
Property | Type | Description |
---|---|---|
$relationName | mixed |
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$primaryKey | mixed |
mixed
|
$localKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$through | mixed |
mixed
|
$primaryKey | mixed |
mixed
|
$throughKey | mixed |
mixed
|
$localKey | mixed |
mixed
|
$secondLocalKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$primaryKey | mixed |
mixed
|
$localKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$through | mixed |
mixed
|
$primaryKey | mixed |
mixed
|
$throughKey | mixed |
mixed
|
$localKey | mixed |
mixed
|
$secondLocalKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
public hasRelation (string $name) : bool
Checks if model has a relationship by supplied name.
Property | Type | Description |
---|---|---|
$name | string |
string
Relation name |
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.
Property | Type | Description |
---|---|---|
$name | string |
string
Relation name |
public makeRelation (string $name) : Winter\Storm\Database\Model | null
Returns a new instance of a related model
Property | Type | Description |
---|---|---|
$name | string |
string
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$name | mixed |
mixed
|
$type | mixed |
mixed
|
$id | mixed |
mixed
|
$localKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$name | mixed |
mixed
|
$type | mixed |
mixed
|
$id | mixed |
mixed
|
$localKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
$type | mixed |
mixed
|
$id | mixed |
mixed
|
$ownerKey | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$name | mixed |
mixed
|
$table | mixed |
mixed
|
$primaryKey | mixed |
mixed
|
$foreignKey | mixed |
mixed
|
$parentKey | mixed |
mixed
|
$relatedKey | mixed |
mixed
|
$inverse | boolean |
boolean
|
$relationName | mixed |
mixed
|
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.
Property | Type | Description |
---|---|---|
$related | mixed |
mixed
|
$name | mixed |
mixed
|
$table | mixed |
mixed
|
$primaryKey | mixed |
mixed
|
$foreignKey | mixed |
mixed
|
$parentKey | mixed |
mixed
|
$relatedKey | mixed |
mixed
|
$relationName | mixed |
mixed
|
protected addRelation (string $type, string $name, array $config) : void
Dynamically add the provided relationship configuration to the local properties
Property | Type | Description |
---|---|---|
$type | string |
string
|
$name | string |
string
|
$config | array |
array
|
protected
getMorphs (string $name, string | null $type = null
, string | null $id = null
)
: array
Get the polymorphic relationship columns.
Property | Type | Description |
---|---|---|
$name | string |
string
|
$type | string | null |
string | null
|
$id | string | null |
string | null
|
protected getRelationCaller ()
Finds the calling function name from the stack trace.
protected getRelationDefaults (string $type) : array
Returns default relation arguments for a given type.
Property | Type | Description |
---|---|---|
$type | string |
string
Relation type |
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.
Property | Type | Description |
---|---|---|
$relationName | string |
string
the relation key, camel-case version |
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.
Property | Type | Description |
---|---|---|
$name | string |
string
|
$type | string |
string
|
$id | string |
string
|
$ownerKey | string |
string
|
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.
Property | Type | Description |
---|---|---|
$target | string |
string
|
$name | string |
string
|
$type | string |
string
|
$id | string |
string
|
$ownerKey | string | null |
string | null
|
protected setRelationValue ($relationName, $value)
Sets a relation value directly from its attribute.
Property | Type | Description |
---|---|---|
$relationName | mixed |
mixed
|
$value | mixed |
mixed
|
protected
validateRelationArgs ($relationName, $optional, array $required = []
)
Validate relation supplied arguments.
Property | Type | Description |
---|---|---|
$relationName | mixed |
mixed
|
$optional | mixed |
mixed
|
$required | array |
array
|
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
|