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
__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
array
protected
get_model( void )
: ICanBoogie\ActiveRecord\Model
Returns the model managing the active record.
Returns the model managing the active record.
Returns
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
string
protected
get_is_new( void )
: boolean
Whether the record is new or not.
Whether the record is new or not.
Returns
boolean
public
save( array $options
= [] )
: boolean|integer
Saves the active record using its model.
Saves the active record using its model.
Parameters
Returns
boolean|integer
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
public
create_validation_rules( void )
: array
Creates validation rules.
Creates validation rules.
Returns
array
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
array
The altered persistent properties
protected
update_primary_key( array|string|integer $primary_key
)
Updates primary key.
Parameters
public
delete( void )
: boolean
Deletes the active record using its model.
Deletes the active record using its model.
Returns
boolean
true
if the record was deleted, false
otherwise.
Throws
Exception
in attempt to delete a record from a model which primary key is empty.
Magic methods summary
public
validate( void )
: ICanBoogie\Validate\ValidationErrors
Validate the active record, returns an array of errors.
Validate the active record, returns an array of errors.
Returns
ICanBoogie\Validate\ValidationErrors
Constants summary
SAVE_SKIP_VALIDATION
: string
'skip_validation'
MODEL_ID
: string
The identifier of the model managing the record.
The identifier of the model managing the record.
null
Properties summary
protected
$model_id
: string
Identifier of the model managing the active record.
Identifier of the model managing the active record.
Note: Due to a PHP bug (or feature), the visibility of the property MUST NOT be private.
https://bugs.php.net/bug.php?id=40412
Magic properties
public read-only
$model_id
: string
The identifier of the model managing the active record.
public read-only
$is_new
: boolean
Whether the record is new or not.