This is the API docs for LemonStand V1, which has been discontinued. LemonStand is now a cloud based platform, available at lemonstand.com.

LemonStand API

Db_DataCollection class

Defined in /phproad/modules/db/classes/db_datacollection.php, lines 11-391
Author LemonStand eCommerce Inc.
Represents a collection of ActiveRecord objects. Objects of this class are returned by Db_ActiveRecord::find_all() method and some other methods and relations.

Public properties

Property Type Description Defined By
parent Db_ActiveRecord a reference to the parent model. Db_DataCollection

Public methods

Method Description Defined By
add() adds an object to the collection. Db_DataCollection
as_array() convert the collection to an array. Db_DataCollection
clear() removes all objects from the collection. Db_DataCollection
collection() returns this collection. Db_DataCollection
count() returns the number of records in the collection. Db_DataCollection
delete() deletes an object from the collection. Db_DataCollection
first() returns a first element in the collection. Db_DataCollection

Property details

parent property

public Db_ActiveRecord $parent;
A reference to the parent model. This field is set only for data collections created by relations.

Method details

add() method

public void add(Db_ActiveRecord $record, string $deferred_session_key=NULL)
$record Db_ActiveRecord specifies a record to add.
$deferred_session_key string optional deferred session key. If the key is specified, it should be used in Db_ActiveRecord::save() method call.
Adds an object to the collection. This method is applicable only when the collection is created by a model's relation. The model should be saved in order the relation changes to apply.

as_array() method

public array as_array(string $field=NULL, string $key_field=NULL)
$field string specifies a name of field which values should be used as array element values.
$key_field string specifies a of the field which values should be used as array element keys.
{return} array returns an array of model objects or scalar values.
Convert the collection to an array. This method can return a list of model objects or their fields, depending on the parameter values. If the $field parameter is NULL, the method returns an array of model objects. Alternatively you can specify the column name and the method will return a list of this column values.
The $key field determines which values should be used as the array keys. By default it matches the record index in the collection. If a field name passed, the field value is used as the array keys.
$array = $collection->as_array(); // Array of model objects
$array = $collection->as_array('name'); // Array of 'name' column values
$array = $collection->as_array('name', 'id'); // Array keys match the 'id' column values.

clear() method

public void clear(string $deferred_session_key=NULL)
$deferred_session_key string optional deferred session key. If the key is specified, it should be used in Db_ActiveRecord::save() method call.
Removes all objects from the collection This method is applicable only when the collection is created by a model's relation. The model should be saved in order the relation changes to apply.

collection() method

public Db_DataCollection collection()
{return} Db_DataCollection returns a collection
Returns this collection. This method simplifies front-end coding.

count() method

public integer count()
{return} integer
Returns the number of records in the collection.

delete() method

public void delete(Db_ActiveRecord $record, string $deferred_session_key=NULL)
$record Db_ActiveRecord specifies a record to remove.
$deferred_session_key string optional deferred session key. If the key is specified, it should be used in Db_ActiveRecord::save() method call.
Deletes an object from the collection This method is applicable only when the collection is created by a model's relation. The model should be saved in order the relation changes to apply.

first() method

public Db_ActiveRecord first()
{return} Db_ActiveRecord returns the model object or NULL.
Returns a first element in the collection.