Allows revisions of database entries to be kept when updates are made.

package Orm
author Fuel Development Team

 Methods

Allow for getter, setter and unset methods

__call(string $method, array $args) : mixed
Inherited

inherited_from \Orm\Model::__call()

Parameters

$method

string

$args

array

Exceptions

\BadMethodCallException

Returns

mixed

__callStatic()

__callStatic($method, $args) 
Inherited

inherited_from \Orm\Model::__callStatic()

Parameters

$method

$args

Allow object cloning to new object

__clone() 
Inherited

inherited_from \Orm\Model::__clone()

Constructor

__construct($data, $new, $view, $cache) 
Inherited

inherited_from \Orm\Model::__construct()

Parameters

$data

array

$new

bool

$view

$cache

Fetch a property or relation

__get($property) : mixed
Inherited

inherited_from \Orm\Model::__get()

Parameters

$property

string

Returns

mixed

Check whether a property exists, only return true for table columns, relations, eav and custom data

__isset(string $property) : bool
Inherited

inherited_from \Orm\Model::__isset()

Parameters

$property

string

Returns

bool

Set a property or relation

__set($property, $value) : \Orm\Model
Inherited

inherited_from \Orm\Model::__set()

Parameters

$property

string

$value

mixed

Returns

Empty a property, relation or custom data

__unset(string $property) 
Inherited

inherited_from \Orm\Model::__unset()

Parameters

$property

string

_init()

_init() 

Fetch or set relations on this object To be used only after having fetched them from the database!

_relate(array | bool | null $rels) : void | array
Inherited

inherited_from \Orm\Model::_relate()

Parameters

$rels

arrayboolnull

Exceptions

\FuelException Invalid input for _relate(), should be an array
\Orm\FrozenObject No changes allowed

Returns

voidarray

Update the original setting for this object

_update_original(array | null $original) 
Inherited

inherited_from \Orm\Model::_update_original()

Parameters

$original

arraynull

Update the original relations for this object

_update_original_relations($relations) 
Inherited

inherited_from \Orm\Model::_update_original_relations()

Parameters

$relations

Attempt to retrieve an earlier loaded object

cached_object(array | \Orm\Model $obj, null | string $class) : \Orm\Model | false
Inherited

inherited_from \Orm\Model::cached_object()

Parameters

$obj

array\Orm\Model

$class

nullstring

Returns

\Orm\Modelfalse

Get a defined condition for this class

condition(string $type) : array
Inherited

inherited_from \Orm\Model::condition()

Parameters

$type

string

type of condition to return

Returns

array

Fetch the database connection name to use

connection(bool $writeable) : null | string
Inherited

inherited_from \Orm\Model::connection()

Parameters

$writeable

bool

if true return the writeable connection (if set)

Returns

nullstring

Count entries, optionally only those matching the $options

count(array $options) : int
Inherited

inherited_from \Orm\Model::count()

Parameters

$options

array

Returns

int

current()

current() 
Inherited

inherited_from \Orm\Model::current()

Delete current object

delete(mixed $cascade, bool $use_transaction) : \Orm\Model

Parameters

$cascade

mixed

null = use default config, bool = force/prevent cascade, array cascades only the relations that are in the array

$use_transaction

bool

Exceptions

\Exception

Returns

\Orm\Modelthis instance as a new object without primary key(s)

Disable an observer event

disable_event(string $event) : void
Inherited

inherited_from \Orm\Model::disable_event()

Parameters

$event

string

event to disable

Enable a defined observer

enable_event(string $event) : void
Inherited

inherited_from \Orm\Model::enable_event()

Parameters

$event

string

class name of the observer (including namespace)

Overrides the default find method to allow the latest revision to be found by default.

find(\Orm\type $id, array $options) : \Orm\type

If any new options to find are added the switch statement will have to be updated too.

Parameters

$id

\Orm\type

$options

array

Exceptions

\FuelException

Returns

\Orm\type

Finds a specific revision for the given ID.

find_revision(\Orm\type $id, int $timestamp, array $relations) : \Orm\Subclass

If a timestamp is specified the revision returned will reflect the entity's state at that given time. This will also load relations when requested.

Parameters

$id

\Orm\type

$timestamp

int

Null to get the latest revision (Same as find($id))

$relations

array

Names of the relations to load.

Returns

\Orm\Subclassof Orm\Model_Temporal

Returns a list of revisions between the given times with the most recent first.

find_revisions_between(int | string $id, \Orm\timestamp $earliestTime, \Orm\timestamp $latestTime) 

This does not load relations.

Parameters

$id

intstring

$earliestTime

\Orm\timestamp

$latestTime

\Orm\timestamp

Flush the object cache

flush_cache(null | string | object $class) 
Inherited

inherited_from \Orm\Model::flush_cache()

Parameters

$class

nullstringobject

Create a new model instance

forge($data, $new, $view, $cache) 
Inherited

inherited_from \Orm\Model::forge()

Parameters

$data

$new

$view

$cache

Freeze the object to disallow changing it or saving it

freeze() 
Inherited

inherited_from \Orm\Model::freeze()

Allow populating this object from an array, and any related objects

from_array(array $values) : \Orm\Model
Inherited

inherited_from \Orm\Model::from_array()

Parameters

$values

array

assoc array with named values to store in the object

Returns

\Orm\Modelthis instance as a new object without primary key(s)

Check whether the object was frozen

frozen() : boolean
Inherited

inherited_from \Orm\Model::frozen()

Returns

boolean

Overrides Model::get() to allow lazy loaded relations to be filtered temporaly.

get(string $property, array $conditions) : mixed

Gets a property or relation from the object

Parameters

$property

string

$conditions

Returns

mixed

Returns an array of the primary keys that are not related to temporal timestamp information.

getNonTimestampPks() 

Generates an array with keys new & old that contain ONLY the values that differ between the original and the current unsaved model.

get_diff() : array
Inherited

Note: relations are given as single or array of imploded pks

inherited_from \Orm\Model::get_diff()

Returns

array

Returns a list of properties and their information with _to_array_exclude properties removed.

get_filtered_properties() : array
Inherited

inherited_from \Orm\Model::get_filtered_properties()

Returns

array

Provide the identifying details in the form of an array

get_pk_assoc() : array
Inherited

inherited_from \Orm\Model::get_pk_assoc()

Returns

array

Returns a list of properties that will be excluded when to_array() is used.

get_to_array_exclude() : array
Inherited

inherited_from \Orm\Model::get_to_array_exclude()

Returns

array

Compare current state with the retrieved state

is_changed(string | array $property) : bool
Inherited

inherited_from \Orm\Model::is_changed()

Parameters

$property

stringarray

Exceptions

\OutOfBoundsException

Returns

bool

is_fetched()

is_fetched($relation) 
Inherited

inherited_from \Orm\Model::is_fetched()

Parameters

$relation

is_new()

is_new() 
Inherited

inherited_from \Orm\Model::is_new()

key()

key() 
Inherited

inherited_from \Orm\Model::key()

Find the maximum

max($key) : bool | int
Inherited

inherited_from \Orm\Model::max()

Parameters

$key

mixed

Returns

boolintMaximum value or false

Find the minimum

min($key) : object | array
Inherited

inherited_from \Orm\Model::min()

Parameters

$key

mixed

Returns

objectarray

Calls all observers for the current event

observe($event) 
Inherited

inherited_from \Orm\Model::observe()

Parameters

$event

string

Get the class's observers and what they observe

observers(string $specific, mixed $default) : array
Inherited

inherited_from \Orm\Model::observers()

Parameters

$specific

string

specific observer to retrieve info of, allows direct param access by using dot notation

$default

mixed

default return value when specific key wasn't found

Returns

array

offsetExists()

offsetExists($offset) 
Inherited

inherited_from \Orm\Model::offsetExists()

Parameters

$offset

offsetGet()

offsetGet($offset) 
Inherited

inherited_from \Orm\Model::offsetGet()

Parameters

$offset

offsetSet()

offsetSet($offset, $value) 
Inherited

inherited_from \Orm\Model::offsetSet()

Parameters

$offset

$value

offsetUnset()

offsetUnset($offset) 
Inherited

inherited_from \Orm\Model::offsetUnset()

Parameters

$offset

ALlows an entry to be updated without having to insert a new row.

overwrite($cascade, $use_transaction) 

This will not record any changed data as a new revision.

Takes the same options as Model::save()

Parameters

$cascade

$use_transaction

Overrides the parent primary_key method to allow primaray key enforcement to be turned off when updating a temporal model.

primary_key() : array

Returns

array

Get the class's properties

properties() : array
Inherited

inherited_from \Orm\Model::properties()

Exceptions

\FuelException Listing columns failed

Returns

array

Fetches a property description array, or specific data from it

property(string $key, mixed $default) : mixed
Inherited

inherited_from \Orm\Model::property()

Parameters

$key

string

property or property.key

$default

mixed

return value when key not present

Returns

mixed

Deletes all revisions of this entity permantly.

purge() 

Overrides Model::query to provide a Temporal_Query

query(array $options) : \Orm\Query_Temporal

Parameters

$options

array

Returns

Register an observer

register_observer(string $name, mixed $options) : void
Inherited

inherited_from \Orm\Model::register_observer()

Parameters

$name

string

class name of the observer (including namespace)

$options

mixed

observer options

Get the class's relations

relations(bool $specific) : \Orm\HasOne | \Orm\HasMany | \Orm\ManyMany | \Orm\Belongsto | \Orm\HasOne[] | \Orm\HasMany[] | \Orm\ManyMany[] | \Orm\Belongsto[]
Inherited

inherited_from \Orm\Model::relations()

Parameters

$specific

bool

Returns

Reset values to those gotten from the database

reset() 
Inherited

inherited_from \Orm\Model::reset()

Restores the entity to this state.

restore() : boolean

Returns

boolean

rewind()

rewind() 
Inherited

inherited_from \Orm\Model::rewind()

Enable sanitization mode in the object

sanitize() : \Orm\Model_Temporal
Inherited

inherited_from \Orm\Model::sanitize()
fluent This method is part of a fluent interface and will return the same instance

Returns

Returns the current sanitization state of the object

sanitized() : bool
Inherited

inherited_from \Orm\Model::sanitized()

Returns

bool

Overrides the save method to allow temporal models to be

save(boolean $cascade, boolean $use_transaction) : boolean

Parameters

$cascade

boolean

$use_transaction

boolean

Returns

boolean

Set

set(string | array $property, string $value) : \Orm\Model
Inherited

Sets a property or relation of the object

access public
inherited_from \Orm\Model::set()

Parameters

$property

stringarray

$value

string

in case $property is a string

Exceptions

\FuelException Primary key on model cannot be changed
\InvalidArgumentException You need to pass both a property name and a value to set()
\Orm\FrozenObject No changes allowed

Returns

Sets the connection to use for this model.

set_connection(string $connection) 
Inherited

inherited_from \Orm\Model::set_connection()

Parameters

$connection

string

Method for use with Fieldset::add_model()

set_form_fields(\Orm\Fieldset $form, array | \Orm\Model $instance) 
Inherited

inherited_from \Orm\Model::set_form_fields()

Parameters

$form

\Orm\Fieldset

Fieldset instance to add fields to

$instance

array\Orm\Model

Model instance or array for use to repopulate

Sets the write connection to use for this model.

set_write_connection(string $connection) 
Inherited

inherited_from \Orm\Model::set_write_connection()

Parameters

$connection

string

Get the table name for this class

table() : string
Inherited

inherited_from \Orm\Model::table()

Returns

string

Gets the temporal properties.

temporal_properties() : array

Mostly stolen from the parent class properties() function

Returns

array

Fetches temporal property description array, or specific data from it.

temporal_property(string $key, mixed $default) : mixed

Stolen from parent class.

Parameters

$key

string

property or property.key

$default

mixed

return value when key not present

Returns

mixed

Allow converting this object to a real object

to_object($custom, $recurse) : object
Inherited

inherited_from \Orm\Model::to_object()

Parameters

$custom

$recurse

Returns

object

Unfreeze the object to allow changing it or saving it again

unfreeze() 
Inherited

inherited_from \Orm\Model::unfreeze()

Unregister an observer

unregister_observer(string $name) : void
Inherited

inherited_from \Orm\Model::unregister_observer()

Parameters

$name

string

class name of the observer (including namespace)

Disable sanitization mode in the object

unsanitize() : \Orm\Model_Temporal
Inherited

inherited_from \Orm\Model::unsanitize()
fluent This method is part of a fluent interface and will return the same instance

Returns

Overrides update to remove PK checking when performing an update.

update() 

valid()

valid() 
Inherited

inherited_from \Orm\Model::valid()

Fetch the model's views

views() : array
Inherited

inherited_from \Orm\Model::views()

Exceptions

\InvalidArgumentException Database view is defined without columns

Returns

array

EAV attribute getter.

_get_eav($attribute, $isset, $unset) : mixed
Inherited

Also deals with isset() and unset()

inherited_from \Orm\Model::_get_eav()

Parameters

$attribute

$isset

$unset

Exceptions

\OutOfBoundsException if the defined EAV relation does not exist or of the wrong type

Returns

mixed

Sanitizatize a data value

_sanitize(string $field, mixed $value) : mixed
Inherited

inherited_from \Orm\Model::_sanitize()

Parameters

$field

string

Name of the property that is being sanitized

$value

mixed

Value to sanitize

Returns

mixed

EAV attribute setter

_set_eav(string $attribute, string $value) : mixed
Inherited

inherited_from \Orm\Model::_set_eav()

Parameters

$attribute

string

$value

string

Exceptions

\OutOfBoundsException

Returns

mixed

Allows correct PKs to be added when performing updates

add_primary_keys_to_where(\Orm\Query $query) 

Parameters

$query

\Orm\Query

Save using INSERT

create() 
Inherited

inherited_from \Orm\Model::create()

Deletes this model instance from the database.

delete_self() : bool
Inherited

inherited_from \Orm\Model::delete_self()

Returns

bool

Allows subclasses to more easily define if a relation can be cascade deleted or not.

should_cascade_delete(array $rel) : bool
Inherited

inherited_from \Orm\Model::should_cascade_delete()

Parameters

$rel

array

Returns

boolFalse to stop the relation from being deleted. Works the same as the cascade_delete property

Makes all PKs returned

disable_id_only_primary_key() 

Disables PK checking

disable_primary_key_check() 

Makes only id returned as PK

enable_id_only_primary_key() 

Enables PK checking

enable_primary_key_check() 

Returns true if the PK should only contain the ID.

get_primary_key_id_only_status() 

Defaults to false

Returns true if the PK checking should be performed.

get_primary_key_status() 

Defaults to true

When a timestamp is set any query objects produced by this temporal model will behave the same as find_revision()

make_query_temporal(array $timestamp) 

Parameters

$timestamp

array

set_lazy_timestamp()

set_lazy_timestamp($timestamp) 

Parameters

$timestamp

 Properties

 

<p>array of fetched objects</p>

$_cached_objects : array
Inherited

inherited_from \Orm\Model::$$_cached_objects
 

<p>Name of DB connection to use</p>

$_connection : string
Inherited

inherited_from \Orm\Model::$$_connection
 

<p>storage for custom properties on this object</p>

$_custom_data : array
Inherited

inherited_from \Orm\Model::$$_custom_data
 

<p>keeps the current state of the object</p>

$_data : array
Inherited

inherited_from \Orm\Model::$$_data
 

$_data_relations

$_data_relations : array
Inherited

inherited_from \Orm\Model::$$_data_relations
 

<p>disabled observer events</p>

$_disabled_events : array
Inherited

inherited_from \Orm\Model::$$_disabled_events
 

<p>keeps to object frozen</p>

$_frozen : bool
Inherited

inherited_from \Orm\Model::$$_frozen
 

<p>keeps track of whether it's a new object</p>

$_is_new : bool
Inherited

inherited_from \Orm\Model::$$_is_new
 

$_iterable

$_iterable 
Inherited

inherited_from \Orm\Model::$$_iterable
 

Contains the filtering status for temporal queries

$_lazy_filtered_classes 

 

If the model has been loaded through find_revision then this will be set to the timestamp used to find the revision.

$_lazy_timestamp 

 

<p>cached observers</p>

$_observers_cached : array
Inherited

inherited_from \Orm\Model::$$_observers_cached
 

<p>keeps a copy of the object as it was retrieved from the database</p>

$_original : array
Inherited

inherited_from \Orm\Model::$$_original
 

<p>keeps a copy of the relation ids that were originally retrieved from the database</p>

$_original_relations : array
Inherited

inherited_from \Orm\Model::$$_original_relations
 

Contains the status of the primary key disable flag for temporal models

$_pk_check_disabled 

 

Contains the status for classes that defines if primaryKey() should return just the ID.

$_pk_id_only 

 

Compound primary key that includes the start and end times is required

$_primary_key : array

 

<p>cached properties</p>

$_properties_cached : array
Inherited

inherited_from \Orm\Model::$$_properties_cached
 

<p>relationships</p>

$_relations_cached : string
Inherited

inherited_from \Orm\Model::$$_relations_cached
 

<p>keeps track of relations that need to be reset before saving the new ones</p>

$_reset_relations : array
Inherited

inherited_from \Orm\Model::$$_reset_relations
 

<p>If this is a records data will be sanitized on get</p>

$_sanitization_enabled : bool
Inherited

inherited_from \Orm\Model::$$_sanitization_enabled
 

<p>cached tables</p>

$_table_names_cached : array
Inherited

inherited_from \Orm\Model::$$_table_names_cached
 

Override to change default temporal paramaters

$_temporal 

 

Contains cached temporal properties.

$_temporal_cached 

 

<p>name or columns that need to be excluded from any to_array() result</p>

$_to_array_exclude : array
Inherited

inherited_from \Orm\Model::$$_to_array_exclude
 

<p>array of valid relation types</p>

$_valid_relations : array
Inherited

inherited_from \Orm\Model::$$_valid_relations
 

<p>view name when used</p>

$_view : string
Inherited

inherited_from \Orm\Model::$$_view
 

<p>cached properties</p>

$_views_cached : array
Inherited

inherited_from \Orm\Model::$$_views_cached
 

<p>Name of the DB connection to use when writing</p>

$_write_connection : string
Inherited

inherited_from \Orm\Model::$$_write_connection
 

<p>global array to track circular references in to_array()</p>

$to_array_references : array
Inherited

inherited_from \Orm\Model::$$to_array_references