Class ActiveRecord
Active Record facilitates the creation and use of business objects whose data require persistent storage via database.
- ICanBoogie\Prototyped
- ┗ ICanBoogie\ActiveRecord
Methods summary
public
__construct( string|ICanBoogie\ActiveRecord\Model
|null $model
= null )
Initializes the $model and ICanBoogie\ActiveRecord::$model_id
properties.
Initializes the $model and ICanBoogie\ActiveRecord::$model_id
properties.
Parameters
$model
The model managing the active record. A
ICanBoogie\ActiveRecord\Model
instance can be specified as well as a model identifier. If a model identifier is specified, the model is resolved when the $model property is accessed. If$model
is empty, the identifier of the model is read from theICanBoogie\ActiveRecord::MODEL_ID
class constant.
Throws
if $model is neither a model identifier nor a
ICanBoogie\ActiveRecord\Model
instance.
public
__sleep( void )
Removes the $model property.
Removes the $model property.
Properties whose value are instances of the ICanBoogie\ActiveRecord
class are removed from the
exported properties.
public
__debugInfo( void )
: array
Removes model
from the output, since model_id
is good enough to figure which model
is used.
Removes model
from the output, since model_id
is good enough to figure which model
is used.
Returns
protected
get_model( void )
: ICanBoogie\ActiveRecord\Model
Returns the model managing the active record.
protected
get_model_id( void )
: string
Returns the identifier of the model managing the active record.
Returns the identifier of the model managing the active record.
Returns
protected
get_is_new( void )
: boolean
Whether the record is new or not.
Whether the record is new or not.
Returns
public
save( array $options
= [] )
: boolean|integer
Saves the active record using its model.
Saves the active record using its model.
Parameters
$options
- Save options.
Returns
Primary key value of the active record, or a boolean if the primary key is not a serial.
public
assert_is_valid( void )
: ICanBoogie\ActiveRecord
Assert that a record is valid.
Assert that a record is valid.
Returns
Throws
ICanBoogie\ActiveRecord\RecordNotValid
if the record is not valid.
public
create_validation_rules( void )
: array
Creates validation rules.
Creates validation rules.
Returns
protected
alter_persistent_properties( array $properties
, ICanBoogie\ActiveRecord\Schema
$schema
)
: array
Unless it's an acceptable value for a column, columns with null
values are discarded.
This way, we don't have to define every properties before saving our active record.
Unless it's an acceptable value for a column, columns with null
values are discarded.
This way, we don't have to define every properties before saving our active record.
Parameters
$properties
$schema
- The model's extended schema.
Returns
The altered persistent properties