ICanBoogie
  • Documentation
  • API Reference
  • ActiveRecord 4.0.x
Namespaces
  • ICanBoogie
    • ActiveRecord
      • ActiveRecordCache
      • Driver
      • Property
      • Validate
        • Reader
        • Validator
        • ValidatorProvider
Classes
  • BelongsToRelation
  • Connection
  • ConnectionCollection
  • ConnectionOptions
  • HasManyRelation
  • Model
  • ModelCollection
  • ModelProvider
  • Query
  • Relation
  • RelationCollection
  • RelationNotDefined
  • Schema
  • SchemaColumn
  • Statement
  • Table
Interfaces
  • ActiveRecordCache
  • Driver
  • Exception
Exceptions
  • ActiveRecordClassNotValid
  • ConnectionAlreadyEstablished
  • ConnectionNotDefined
  • ConnectionNotEstablished
  • DriverNotDefined
  • ModelAlreadyInstantiated
  • ModelNotDefined
  • RecordNotFound
  • RecordNotValid
  • ScopeNotDefined
  • StatementInvocationFailed
  • StatementNotValid
  • UnableToSetFetchMode

Class Model

Base class for activerecord models.

ICanBoogie\Prototyped
┗ ICanBoogie\ActiveRecord\Table
┗ ICanBoogie\ActiveRecord\Model implements ArrayAccess
Namespace: ICanBoogie\ActiveRecord
Located at ActiveRecord/Model.php

Methods summary

protected get_models( void )
protected get_parent_model( void ) : ICanBoogie\ActiveRecord\Model

Return the parent mode.

Return the parent mode.

Returns

ICanBoogie\ActiveRecord\Model
protected get_relations( void ) : ICanBoogie\ActiveRecord\RelationCollection

Return the relations of this model to other models.

Return the relations of this model to other models.

Returns

ICanBoogie\ActiveRecord\RelationCollection
protected lazy_get_activerecord_cache( void ) : ICanBoogie\ActiveRecord\ActiveRecordCache

Returns the records cache.

Returns the records cache.

Note: The method needs to be implemented through prototype bindings.

Returns

ICanBoogie\ActiveRecord\ActiveRecordCache
public __construct( ICanBoogie\ActiveRecord\ModelCollection $models, array $attributes )

Override the constructor to provide support for the ICanBoogie\ActiveRecord\Model::ACTIVERECORD_CLASS tag and extended support for the ICanBoogie\ActiveRecord\Table::EXTENDING tag.

Override the constructor to provide support for the ICanBoogie\ActiveRecord\Model::ACTIVERECORD_CLASS tag and extended support for the ICanBoogie\ActiveRecord\Table::EXTENDING tag.

If ICanBoogie\ActiveRecord\Table::EXTENDING is defined but the model has no schema (ICanBoogie\ActiveRecord\Table::SCHEMA is empty), the name of the model and the schema are inherited from the extended model and ICanBoogie\ActiveRecord\Table::EXTENDING is set to the parent model object. If ICanBoogie\ActiveRecord\Model::ACTIVERECORD_CLASS is empty, its value is set to the extended model's active record class.

If ICanBoogie\ActiveRecord\Model::ACTIVERECORD_CLASS is set, its value is saved in the ICanBoogie\ActiveRecord\Model::$activerecord_class property.

Parameters

$models
$attributes
Attributes used to construct the model.

Throws

InvalidArgumentException
if the ICanBoogie\ActiveRecord\Table::CONNECTION attribute is empty.

Overrides

ICanBoogie\ActiveRecord\Table::__construct
public __debugInfo( void )
public __call( $method, $arguments )

Handles query methods, dynamic filters, scopes, and relations.

Handles query methods, dynamic filters, scopes, and relations.

Inheritdoc

public __get( $property )

Overrides the method to handle scopes.

Overrides the method to handle scopes.

Inheritdoc

protected get_id( void ) : string

Returns the identifier of the model.

Returns the identifier of the model.

Returns

string
protected get_activerecord_class( void ) : string

Returns the class of the active records of the model.

Returns the class of the active records of the model.

Returns

string
public find( mixed $key ) : ICanBoogie\ActiveRecord|ICanBoogie\ActiveRecord[]

Finds a record or a collection of records.

Finds a record or a collection of records.

Parameters

$key
A key, multiple keys, or an array of keys.

Returns

ICanBoogie\ActiveRecord|ICanBoogie\ActiveRecord[]
A record or a set of records.

Throws

ICanBoogie\ActiveRecord\RecordNotFound

when the record, or one or more records of the records set, could not be found.

public save( array $properties, mixed|null $key = null, array $options = [] ) : mixed

Because records are cached, we need to remove the record from the cache when it is saved, so that loading the record again returns the updated record, not the one in the cache.

Because records are cached, we need to remove the record from the cache when it is saved, so that loading the record again returns the updated record, not the one in the cache.

Parameters

$properties
$values
$key
$id
$options

Returns

mixed

Throws

Exception

Inheritdoc

Overrides

ICanBoogie\ActiveRecord\Table::save
public delete( mixed $key ) : boolean

Eliminates the record from the cache.

Eliminates the record from the cache.

Parameters

$key
Identifier of the record.

Returns

boolean

Inheritdoc

Overrides

ICanBoogie\ActiveRecord\Table::delete
protected get_exists( void ) : boolean

Checks that the SQL table associated with the model exists.

Checks that the SQL table associated with the model exists.

Returns

boolean
protected get_count( void ) : integer

Returns the number of records of the model.

Returns the number of records of the model.

Returns

integer
protected get_all( void ) : ICanBoogie\ActiveRecord[]

Returns all the records of the model.

Returns all the records of the model.

Returns

ICanBoogie\ActiveRecord[]
protected get_one( void ) : ICanBoogie\ActiveRecord

Returns the first record of the model.

Returns the first record of the model.

Returns

ICanBoogie\ActiveRecord
public has_scope( string $name ) : boolean

Checks if the model has a given scope.

Checks if the model has a given scope.

Scopes are defined using method with the "scope_" prefix. As an example, the visible scope can be defined by implementing the scope_visible method.

Parameters

$name
Scope name.

Returns

boolean
public scope( string $scope_name, array $scope_args = [] ) : ICanBoogie\ActiveRecord\Query

Invokes a given scope.

Invokes a given scope.

Parameters

$scope_name
Name of the scope to apply to the query.
$scope_args

Arguments to forward to the scope method. The first argument must be a ICanBoogie\ActiveRecord\Query instance.

Returns

ICanBoogie\ActiveRecord\Query

Throws

ICanBoogie\ActiveRecord\ScopeNotDefined
when the specified scope is not defined.
public offsetSet( $offset, $value )

Throws

ICanBoogie\OffsetNotWritable
when one tries to write an offset.

Inheritdoc

Implementation of

ArrayAccess::offsetSet()
public offsetExists( integer $key ) : boolean

Alias to exists().

Alias to exists().

Parameters

$key
ActiveRecord identifier.

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public offsetUnset( integer $key )

Alias to ICanBoogie\ActiveRecord\Model::delete().

Alias to ICanBoogie\ActiveRecord\Model::delete().

Parameters

$key
ActiveRecord identifier.

Implementation of

ArrayAccess::offsetUnset()
public offsetGet( integer $key ) : ICanBoogie\ActiveRecord

Alias to ICanBoogie\ActiveRecord\Model::find().

Alias to ICanBoogie\ActiveRecord\Model::find().

Parameters

$key
ActiveRecord identifier.

Returns

ICanBoogie\ActiveRecord

Implementation of

ArrayAccess::offsetGet()
protected new_record( array $properties = [] ) : ICanBoogie\ActiveRecord

Creates a new ActiveRecord instance.

Creates a new ActiveRecord instance.

The class of the instance is defined by the ICanBoogie\ActiveRecord\Model::$activerecord_class property.

Parameters

$properties
Optional properties to instantiate the record with.

Returns

ICanBoogie\ActiveRecord

Methods inherited from ICanBoogie\ActiveRecord\Table

__invoke(), assert_has_connection(), assert_has_name(), assert_has_schema(), assert_implements_is_valid(), assert_parent_is_valid(), construct_with_parent(), drop(), ensure_has_alias(), execute(), filter_values(), get_alias(), get_connection(), get_name(), get_parent(), get_primary(), get_schema(), get_schema_options(), get_unprefixed_name(), insert(), install(), is_installed(), lazy_get_extended_schema(), lazy_get_select_join(), lazy_get_update_join(), map_construct_attributes(), prepare(), query(), quote(), resolve_statement(), save_callback(), truncate(), uninstall(), update()

Magic methods summary

public select( void ) : ICanBoogie\ActiveRecord\Query

select($expression) The method is forwarded to Query::select.

select($expression) The method is forwarded to Query::select.

Returns

ICanBoogie\ActiveRecord\Query
public join( void ) : ICanBoogie\ActiveRecord\Query

join($expression) The method is forwarded to Query::join.

join($expression) The method is forwarded to Query::join.

Returns

ICanBoogie\ActiveRecord\Query
public where( void ) : ICanBoogie\ActiveRecord\Query

where($conditions, $conditions_args = null, $_ = null) The method is forwarded to Query::where.

where($conditions, $conditions_args = null, $_ = null) The method is forwarded to Query::where.

Returns

ICanBoogie\ActiveRecord\Query
public group( void ) : ICanBoogie\ActiveRecord\Query

group($group) The method is forwarded to Query::group.

group($group) The method is forwarded to Query::group.

Returns

ICanBoogie\ActiveRecord\Query
public order( void ) : ICanBoogie\ActiveRecord\Query

order($order) The method is forwarded to Query::order.

order($order) The method is forwarded to Query::order.

Returns

ICanBoogie\ActiveRecord\Query
public limit( void ) : ICanBoogie\ActiveRecord\Query

limit($limit, $offset = null) The method is forwarded to Query::limit.

limit($limit, $offset = null) The method is forwarded to Query::limit.

Returns

ICanBoogie\ActiveRecord\Query
public offset( void ) : ICanBoogie\ActiveRecord\Query

offset($offset) The method is forwarded to Query::offset.

offset($offset) The method is forwarded to Query::offset.

Returns

ICanBoogie\ActiveRecord\Query
public exists( void ) : boolean

exists($key = null) The method is forwarded to Query::exists.

exists($key = null) The method is forwarded to Query::exists.

Returns

boolean
public count( void ) : mixed

count($column = null) The method is forwarded to Query::count.

count($column = null) The method is forwarded to Query::count.

Returns

mixed
public average( void ) : string

average($column) The method is forwarded to Query::average.

average($column) The method is forwarded to Query::average.

Returns

string
public maximum( void ) : string

maximum($column) The method is forwarded to Query::maximum.

maximum($column) The method is forwarded to Query::maximum.

Returns

string
public minimum( void ) : string

minimum($column) The method is forwarded to Query::minimum.

minimum($column) The method is forwarded to Query::minimum.

Returns

string
public sum( void ) : integer

sum($column) The method is forwarded to Query::sum.

sum($column) The method is forwarded to Query::sum.

Returns

integer
public all( void ) : array

all() The method is forwarded to Query::all.

all() The method is forwarded to Query::all.

Returns

array
public one( void ) : ICanBoogie\ActiveRecord

one() The method is forwarded to Query::one.

one() The method is forwarded to Query::one.

Returns

ICanBoogie\ActiveRecord
public new( void ) : ICanBoogie\ActiveRecord

new(array $properties = []) Instantiate a new record.

new(array $properties = []) Instantiate a new record.

Returns

ICanBoogie\ActiveRecord
public belongs_to( void ) : ICanBoogie\ActiveRecord\Model

belongs_to(...$args) Adds a belongs_to relation.

belongs_to(...$args) Adds a belongs_to relation.

Returns

ICanBoogie\ActiveRecord\Model
public has_many( void ) : ICanBoogie\ActiveRecord\Model

has_many($related, $options = []) Adds a has_many relation.

has_many($related, $options = []) Adds a has_many relation.

Returns

ICanBoogie\ActiveRecord\Model

Constants summary

ACTIVERECORD_CLASS : string
'activerecord_class'
BELONGS_TO : string
'belongs_to'
CLASSNAME : string
'class'
HAS_MANY : string
'has_many'
ID : string
'id'

Constants inherited from ICanBoogie\ActiveRecord\Table

ALIAS, CONNECTION, EXTENDING, IMPLEMENTING, NAME, SCHEMA

Properties summary

protected $activerecord_class : string

Active record instances class.

Active record instances class.


		
protected $attributes : array[string]mixed

Attributes of the model.

Attributes of the model.


		
protected $parent_model : ICanBoogie\ActiveRecord\Model

The parent model of the model.

The parent model of the model.

The parent model and the ICanBoogie\ActiveRecord\Table::$parent may be different if the model does not have a schema but inherits it from its parent.


		
protected $relations : ICanBoogie\ActiveRecord\RelationCollection

The relations of this model to other models.

The relations of this model to other models.


		

Properties inherited from ICanBoogie\ActiveRecord\Table

$alias, $connection, $implements, $name, $parent, $primary, $schema, $schema_options, $select_join, $unprefixed_name, $update_join

Magic properties

public $activerecord_cache : ICanBoogie\ActiveRecord\ActiveRecordCache

The cache use to store activerecords.

public read-only $parent : ICanBoogie\ActiveRecord\Model|null

Parent model.

public read-only $models : ICanBoogie\ActiveRecord\ModelCollection
public read-only $all : array

Retrieve all the records from the model.

public read-only $activerecord_class : string

Class of the active records of the model.

public read-only $count : integer

The number of records of the model.

public read-only $exists : boolean

Whether the SQL table associated with the model exists.

public read-only $id : string

The identifier of the model.

public read-only $one : ICanBoogie\ActiveRecord

Retrieve the first record from the mode.

public read-only $parent_model : ICanBoogie\ActiveRecord\Model

The parent model.

public read-only $relations : ICanBoogie\ActiveRecord\Relation[]

The relations of this model to other models.

Magic properties inherited from ICanBoogie\ActiveRecord\Table

$alias, $connection, $extended_schema, $name, $primary, $schema, $schema_options, $unprefixed_name

ActiveRecord 4.0.x – Check on GitHub – API documentation generated by ApiGen