Class RelationCollection
Relation collection of a model.
-
ICanBoogie\ActiveRecord\RelationCollection
implements
ArrayAccess
uses
ICanBoogie\Accessor\AccessorTrait (not available)
Methods summary
protected
get_model( void )
public
offsetExists( string $relation_name
)
: boolean
Checks if a relation exists.
Checks if a relation exists.
Parameters
Returns
boolean
Implementation of
ArrayAccess::offsetExists()
public
offsetGet( string $relation_name
)
: ICanBoogie\ActiveRecord\Relation
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
belongs_to( string|array $belongs_to
)
: ICanBoogie\ActiveRecord\Model
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
has_many( ICanBoogie\ActiveRecord\Model
|string $related
, array $options
= [] )
: ICanBoogie\ActiveRecord\Model
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
Properties summary
Magic properties