Class RelationCollection
Relation collection of a model.
-
ICanBoogie\ActiveRecord\RelationCollection
implements
ArrayAccess
uses
ICanBoogie\Accessor\AccessorTrait (not available)
Methods summary
protected
|
|
public
|
|
public
boolean
|
#
offsetExists( string $relation_name )
Checks if a relation exists.
Checks if a relation exists.
Parameters
Returns
boolean
Implementation of
ArrayAccess::offsetExists()
|
public
ICanBoogie\ActiveRecord\Relation
|
#
offsetGet( string $relation_name )
Returns a relation.
Parameters
Returns
Throws
Implementation of
ArrayAccess::offsetGet()
|
public
|
#
offsetSet( $relation_name, $relation )
Throws
ICanBoogie\OffsetNotWritable because relations cannot be set.
Implementation of
ArrayAccess::offsetSet()
|
public
|
#
offsetUnset( $relation_name )
Throws
ICanBoogie\OffsetNotWritable because relations cannot be unset.
Implementation of
ArrayAccess::offsetUnset()
|
public
ICanBoogie\ActiveRecord\Model
|
#
belongs_to( string|array $belongs_to )
Add a belongs to relation.
Add a belongs to relation.
$cars->belongs_to([ $drivers, $brands ]);
$cars->belongs_to([ 'drivers', 'brands' ]);
$cars->belongs_to($drivers, $brands);
$cars->belongs_to($drivers)->belongs_to($brands);
$cars->belongs_to([
[ $drivers, [ 'local_key' => 'card_id', 'foreign_key' => 'driver_id' ] ]
[ $brands, [ 'local_key' => 'brand_id', 'foreign_key' => 'brand_id' ] ]
]);
Parameters
Returns
|
public
ICanBoogie\ActiveRecord\Model
|
#
has_many( ICanBoogie\ActiveRecord\Model |string $related, array $options = [] )
Add a one-to-many relation.
Add a one-to-many relation.
$this->has_many('comments');
$this->has_many([ 'comments', 'attachments' ]);
$this->has_many([ [ 'comments', [ 'as' => 'comments' ] ], 'attachments' ]);
Parameters
- $related
The related model can be specified using its instance or its
identifier.
- $options
the following options are available:
local_key : The name of the local key. Default: The parent model's primary key.
foreign_key : The name of the foreign key. Default: The parent model's primary key.
as : The name of the magic property to add to the prototype. Default: a plural name
resolved from the foreign model's id.
Returns
See
|