PHP Class Granada\Orm\Wrapper

You shouldn't need to interact with this class directly. It is used internally by the Model base class.
Inheritance: extends Granada\ORM
Show file Open project: surt/granada Class Usage Examples

Public Properties

Property Type Description
$relationships

Protected Properties

Property Type Description
$_class_name The wrapped find_one and find_many classes will return an instance or instances of this class.

Public Methods

Method Description
__call ( $method, $parameters ) Overrides __call to check for filter_$method names defined You can now define filters methods on the Granada Model as public static function filter_{filtermethodname} and call it from a static call ModelName::filtermethodname->.
assoc_to_keyval ( $assoc = null, boolean | string $key_field = null, boolean | string $val_field = null ) : array Converts a multi-dimensional associative array into an array of key => values with the provided field names
create ( $data = null ) Wrap Idiorm's create method to return an empty instance of the class associated with this wrapper instead of the raw ORM class.
filter ( ) Add a custom filter to the method chain specified on the model class. This allows custom queries to be added to models. The filter should take an instance of the ORM wrapper as its first argument and return an instance of the ORM wrapper. Any arguments passed to this method after the name of the filter will be passed to the called filter function as arguments after the ORM class.
find_many ( ) : array | Granada\ResultSet Tell the ORM that you are expecting multiple results from your query, and execute it. Will return an array of instances of the ORM class, or an empty array if no rows were returned.
find_one ( integer $id = null ) Wrap Idiorm's find_one method to return an instance of the class associated with this wrapper instead of the raw ORM class.
find_pairs ( $key = false, $value = false ) Added: Return pairs as result array('keyrecord_value'=>'valuerecord_value',.
for_table ( $table_name, $connection_name = parent::DEFAULT_CONNECTION ) Factory method, return an instance of this class bound to the supplied table name.
group_by_raw ( $expr ) Add an unquoted expression to the list of columns to GROUP BY
insert ( $rows, $ignore = false ) To create and save multiple elements, easy way Using an array with rows array(array('name'=>'value',.
order_by_raw ( $clause ) Add an unquoted expression as an ORDER BY clause
pluck ( string $column ) : mixed Pluck a single column from the result.
raw_join ( $join ) Create raw_join
reset_relation ( ) : Wrapper Added: Reset relation deletes the relationship "where" condition.
select_raw ( $expr, $alias = null ) Overload select_expr name
set_class_name ( string $class_name ) Set the name of the class which the wrapped methods should return instances of.
where_id_in ( $ids ) Special method to query the table by its primary key
with ( ) : Wrapper Added: Set the eagerly loaded models on the queryable model.

Protected Methods

Method Description
_create_model_instance ( $orm ) Method to create an instance of the model class associated with this wrapper and populate it with the supplied Idiorm instance.
_get_instances ( array $rows ) : array Override Idiorm _instances_with_id_as_key Create instances of each row in the result and map them to an associative array with the primary IDs as the array keys.

Method Details

__call() public method

.....
public __call ( $method, $parameters )

_create_model_instance() protected method

Method to create an instance of the model class associated with this wrapper and populate it with the supplied Idiorm instance.
protected _create_model_instance ( $orm )

_get_instances() protected method

Added: the array result key = primary key from the model Added: Eager loading of relationships defined "with()"
protected _get_instances ( array $rows ) : array
$rows array
return array

assoc_to_keyval() public static method

Converts a multi-dimensional associative array into an array of key => values with the provided field names
public static assoc_to_keyval ( $assoc = null, boolean | string $key_field = null, boolean | string $val_field = null ) : array
$key_field boolean | string
$val_field boolean | string
return array

create() public method

Wrap Idiorm's create method to return an empty instance of the class associated with this wrapper instead of the raw ORM class.
public create ( $data = null )

filter() public method

Add a custom filter to the method chain specified on the model class. This allows custom queries to be added to models. The filter should take an instance of the ORM wrapper as its first argument and return an instance of the ORM wrapper. Any arguments passed to this method after the name of the filter will be passed to the called filter function as arguments after the ORM class.
public filter ( )

find_many() public method

Tell the ORM that you are expecting multiple results from your query, and execute it. Will return an array of instances of the ORM class, or an empty array if no rows were returned.
public find_many ( ) : array | Granada\ResultSet
return array | Granada\ResultSet

find_one() public method

Added: hidrate the model instance before returning
public find_one ( integer $id = null )
$id integer

find_pairs() public method

....)
public find_pairs ( $key = false, $value = false )

for_table() public static method

A repeat of content in parent::for_table, so that created class is ORMWrapper, not ORM
public static for_table ( $table_name, $connection_name = parent::DEFAULT_CONNECTION )

group_by_raw() public method

Add an unquoted expression to the list of columns to GROUP BY
public group_by_raw ( $expr )

insert() public method

..), array('name2'=>'value2',...),..) or a array multiple
public insert ( $rows, $ignore = false )

order_by_raw() public method

Add an unquoted expression as an ORDER BY clause
public order_by_raw ( $clause )

pluck() public method

Pluck a single column from the result.
public pluck ( string $column ) : mixed
$column string
return mixed

raw_join() public method

Create raw_join
public raw_join ( $join )

reset_relation() public method

Added: Reset relation deletes the relationship "where" condition.
public reset_relation ( ) : Wrapper
return Wrapper

select_raw() public method

Overload select_expr name
public select_raw ( $expr, $alias = null )

set_class_name() public method

Set the name of the class which the wrapped methods should return instances of.
public set_class_name ( string $class_name )
$class_name string

where_id_in() public method

Special method to query the table by its primary key
public where_id_in ( $ids )

with() public method

Added: Set the eagerly loaded models on the queryable model.
public with ( ) : Wrapper
return Wrapper

Property Details

$_class_name protected property

The wrapped find_one and find_many classes will return an instance or instances of this class.
protected $_class_name

$relationships public property

public $relationships