Class RelationCollection
Relation collection of a model.
-
ICanBoogie\ActiveRecord\RelationCollection
implements
ArrayAccess
uses
ICanBoogie\Accessor\AccessorTrait (not available)
Methods summary
protected
|
|
public
|
|
public
|
#
offsetExists( $relation_name )
Implementation of
ArrayAccess::offsetExists()
|
public
|
#
offsetGet( $relation_name )
Implementation of
ArrayAccess::offsetGet()
|
public
|
#
offsetSet( $relation_name, $relation )
Implementation of
ArrayAccess::offsetSet()
|
public
|
#
offsetUnset( $relation_name )
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
|