Methods

Allow for getter, setter and unset methods

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

Parameters

$method

string

$args

array

Exceptions

\BadMethodCallException

Returns

mixed

__callStatic()

__callStatic($method, $args) 

Parameters

$method

$args

Allow object cloning to new object

__clone() 

Constructor

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

Parameters

$data

array

$new

bool

$view

$cache

Fetch a property or relation

__get($property) : mixed

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

Parameters

$property

string

Returns

bool

Set a property or relation

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

Parameters

$property

string

$value

mixed

Returns

Empty a property, relation or custom data

__unset(string $property) 

Parameters

$property

string

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

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) 

Parameters

$original

arraynull

Update the original relations for this object

_update_original_relations($relations) 

Parameters

$relations

Attempt to retrieve an earlier loaded object

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

Parameters

$obj

array\Orm\Model

$class

nullstring

Returns

\Orm\Modelfalse

Get a defined condition for this class

condition(string $type) : array

Parameters

$type

string

type of condition to return

Returns

array

Fetch the database connection name to use

connection(bool $writeable) : null | string

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

Parameters

$options

array

Returns

int

current()

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

Parameters

$event

string

event to disable

Enable a defined observer

enable_event(string $event) : void

Parameters

$event

string

class name of the observer (including namespace)

Find one or more entries

find(int | null $id, array $options) : \Orm\Model | \Orm\Model[]

Parameters

$id

intnull

$options

array

Exceptions

\FuelException

Returns

Flush the object cache

flush_cache(null | string | object $class) 

Parameters

$class

nullstringobject

Create a new model instance

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

Parameters

$data

$new

$view

$cache

Freeze the object to disallow changing it or saving it

freeze() 

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

from_array(array $values) : \Orm\Model

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

Returns

boolean

Get

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

Gets a property or relation from the object

access public

Parameters

$property

string

$conditions

array

Returns

mixed

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

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

Returns

array

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

get_filtered_properties() : array

Returns

array

Provide the identifying details in the form of an array

get_pk_assoc() : array

Returns

array

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

get_to_array_exclude() : array

Returns

array

Compare current state with the retrieved state

is_changed(string | array $property) : bool

Parameters

$property

stringarray

Exceptions

\OutOfBoundsException

Returns

bool

is_fetched()

is_fetched($relation) 

Parameters

$relation

is_new()

is_new() 

key()

key() 

Find the maximum

max($key) : bool | int

Parameters

$key

mixed

Returns

boolintMaximum value or false

Find the minimum

min($key) : object | array

Parameters

$key

mixed

Returns

objectarray

Calls all observers for the current event

observe($event) 

Parameters

$event

string

Get the class's observers and what they observe

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

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) 

Parameters

$offset

offsetGet()

offsetGet($offset) 

Parameters

$offset

offsetSet()

offsetSet($offset, $value) 

Parameters

$offset

$value

offsetUnset()

offsetUnset($offset) 

Parameters

$offset

Get the primary key(s) of this class

primary_key() : array

Returns

array

Get the class's properties

properties() : array

Exceptions

\FuelException Listing columns failed

Returns

array

Fetches a property description array, or specific data from it

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

Parameters

$key

string

property or property.key

$default

mixed

return value when key not present

Returns

mixed

Creates a new query with optional settings up front

query($options) : \Orm\Query

Parameters

$options

array

Returns

Register an observer

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

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[]

Parameters

$specific

bool

Returns

Reset values to those gotten from the database

reset() 

rewind()

rewind() 

Enable sanitization mode in the object

sanitize() : \Orm\Model

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

Returns

bool

Save the object and it's relations, create when necessary

save(mixed $cascade, $use_transaction) : bool

Parameters

$cascade

mixed

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

$use_transaction

Returns

bool

Set

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

Sets a property or relation of the object

access public

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) 

Parameters

$connection

string

Method for use with Fieldset::add_model()

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

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) 

Parameters

$connection

string

Get the table name for this class

table() : string

Returns

string

Allow converting this object to a real object

to_object($custom, $recurse) : object

Parameters

$custom

$recurse

Returns

object

Unfreeze the object to allow changing it or saving it again

unfreeze() 

Unregister an observer

unregister_observer(string $name) : void

Parameters

$name

string

class name of the observer (including namespace)

Disable sanitization mode in the object

unsanitize() : \Orm\Model

fluent This method is part of a fluent interface and will return the same instance

Returns

valid()

valid() 

Fetch the model's views

views() : array

Exceptions

\InvalidArgumentException Database view is defined without columns

Returns

array

EAV attribute getter.

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

Also deals with isset() and unset()

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

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

Parameters

$attribute

string

$value

string

Exceptions

\OutOfBoundsException

Returns

mixed

Adds the primary keys in where clauses to the given query.

add_primary_keys_to_where(\Orm\Query $query) 

Parameters

$query

\Orm\Query

Save using INSERT

create() 

Deletes this model instance from the database.

delete_self() : bool

Returns

bool

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

should_cascade_delete(array $rel) : bool

Parameters

$rel

array

Returns

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

Save using UPDATE

update() 

 Properties

 

<p>array of fetched objects</p>

$_cached_objects : array

 

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

$_connection : string

 

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

$_custom_data : array

 

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

$_data : array

 

$_data_relations

$_data_relations : array

 

<p>disabled observer events</p>

$_disabled_events : array

 

<p>keeps to object frozen</p>

$_frozen : bool

 

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

$_is_new : bool

 

$_iterable

$_iterable 

 

<p>cached observers</p>

$_observers_cached : array

 

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

$_original : array

 

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

$_original_relations : array

 

<p>name or names of the primary keys</p>

$_primary_key : array

 

<p>cached properties</p>

$_properties_cached : array

 

<p>relationships</p>

$_relations_cached : string

 

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

$_reset_relations : array

 

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

$_sanitization_enabled : bool

 

<p>cached tables</p>

$_table_names_cached : array

 

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

$_to_array_exclude : array

 

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

$_valid_relations : array

 

<p>view name when used</p>

$_view : string

 

<p>cached properties</p>

$_views_cached : array

 

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

$_write_connection : string

 

<p>whether to allow setting PK's via forge() or from_array()</p>

$block_set_pks : bool

 

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

$to_array_references : array