class Record implements ArrayAccess (View source)

Represents data loaded from a database.

Constants

STATE_INSERT

A record state when new record is being inserted to database

STATE_UPDATE

A record state when existing record is being updated in the database

STATE_DELETE

A record state when the record no longer exists in the database

Methods

__construct(Schema $schema, Model $model = null)

Record constructor.

array
getPrimaryKey()

Returns the primary key for the record as it was at the time the record was loaded.

bool
isEmpty()

Tells if the record is empty, i.e. none of the fields have any values.

bool
isNew()

Tells if the record is new and not yet inserted into the database.

bool
isDeleted()

Tells if the record has been deleted from the database.

void
updateState(int $state)

Updates the state of the record after the appropriate database operation.

getSchema()

Returns the schema for the record data.

getModel()

Returns the model associated with the record and initializes it if has not been initialized yet.

bool
hasReferencedRecords(string $name)

Tells if the referenced records for the given relationship has been loaded.

void
setReferencedRecords(string $name, array $records)

Loads the referenced records for the given relationship.

array
getReferencedRecords(string $name)

Returns the list of referenced records for the given relationship.

void
associate(string $name, Model $model)

Sets the referenced fields in this record to reference the record of the given model.

void
addAssociation(string $name, Model $model)

Sets the referencing fields in the record of the given model to reference this record.

Model|null
getRelatedModel(string $name)

Returns the model of the referenced record in a unique relationship.

array
getRelatedModels(string $name)

Returns list of models referenced by this record via the given relationship.

array
getRelatedModelsByProxy(string $proxy, string $name)

Gets list of models that are referenced by records that this record references.

array
getAllReferencedRecords()

Returns list of records recursively referenced by this record or any referenced record.

void
setDatabaseValues(array $row)

Sets the values for the fields in the record loaded from the database.

array
getDatabaseValues()

Returns the values for the fields in this record for storing in database.

array
getChangedFields()

Returns list of all fields that have been modified since the records state was last updated.

bool
offsetExists(string $offset)

Tells if the value in the given field is other than null.

mixed
offsetGet(string $offset)

Returns the value for the given field.

offsetSet(string $offset, mixed $value)

Sets the value for the given field.

offsetUnset(string $offset)

Sets the value of the given field to null and marks it unchanged, if the record has not yet been inserted.

Details

__construct(Schema $schema, Model $model = null)

Record constructor.

Parameters

Schema $schema The schema for the record data
Model $model The model associated with the record or null if it has not been initialized

array getPrimaryKey()

Returns the primary key for the record as it was at the time the record was loaded.

Return Value

array Associative array of primary key fields and their values

bool isEmpty()

Tells if the record is empty, i.e. none of the fields have any values.

Return Value

bool True if all the fields values are null, false otherwise

bool isNew()

Tells if the record is new and not yet inserted into the database.

Return Value

bool True if the record has not been inserted into database, false otherwise

bool isDeleted()

Tells if the record has been deleted from the database.

Return Value

bool True if the record no longer exists in the database, false otherwise

void updateState(int $state)

Updates the state of the record after the appropriate database operation.

Parameters

int $state The appropriate state depending on the performed database operation

Return Value

void

Schema getSchema()

Returns the schema for the record data.

Return Value

Schema The schema for the record data

Model getModel()

Returns the model associated with the record and initializes it if has not been initialized yet.

Return Value

Model The model associated with the record data

bool hasReferencedRecords(string $name)

Tells if the referenced records for the given relationship has been loaded.

Parameters

string $name Name of the relationship

Return Value

bool True if the referenced records have been loaded, false if not

void setReferencedRecords(string $name, array $records)

Loads the referenced records for the given relationship.

Parameters

string $name Name of the relationship
array $records List of records referenced by this record

Return Value

void

array getReferencedRecords(string $name)

Returns the list of referenced records for the given relationship.

Parameters

string $name Name of the relationship

Return Value

array List of records referenced by this record

void associate(string $name, Model $model)

Sets the referenced fields in this record to reference the record of the given model.

Parameters

string $name Name of the relationship
Model $model The model that this record should be reference

Return Value

void

void addAssociation(string $name, Model $model)

Sets the referencing fields in the record of the given model to reference this record.

Parameters

string $name Name of the relationship
Model $model The model that should reference this record

Return Value

void

Model|null getRelatedModel(string $name)

Returns the model of the referenced record in a unique relationship.

Parameters

string $name Name of the relationship

Return Value

Model|null The referenced model, or null if no model is referenced by this record

array getRelatedModels(string $name)

Returns list of models referenced by this record via the given relationship.

Parameters

string $name Name of the relationship

Return Value

array List of models referenced by this record

array getRelatedModelsByProxy(string $proxy, string $name)

Gets list of models that are referenced by records that this record references.

Parameters

string $proxy Name of the relationship in this record
string $name Name of the relationship in the proxy record

Return Value

array List of models referenced by the records referenced by this record

array getAllReferencedRecords()

Returns list of records recursively referenced by this record or any referenced record.

Return Value

array List of all referenced records and any record they recursively reference

void setDatabaseValues(array $row)

Sets the values for the fields in the record loaded from the database.

Parameters

array $row Value for the fields in this record

Return Value

void

array getDatabaseValues()

Returns the values for the fields in this record for storing in database.

Return Value

array Associative list of fields and their values

array getChangedFields()

Returns list of all fields that have been modified since the records state was last updated.

Return Value

array List of fields updated since last time the state was updated

bool offsetExists(string $offset)

Tells if the value in the given field is other than null.

Parameters

string $offset Name of the field

Return Value

bool True if the value is something else than null, false otherwise

mixed offsetGet(string $offset)

Returns the value for the given field.

Parameters

string $offset Name of the field

Return Value

mixed Value for the given field

offsetSet(string $offset, mixed $value)

Sets the value for the given field.

Parameters

string $offset Name of the field
mixed $value Value for the given field

offsetUnset(string $offset)

Sets the value of the given field to null and marks it unchanged, if the record has not yet been inserted.

Parameters

string $offset The name of the field