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_ActiveRecord class

Defined in /phproad/modules/db/classes/db_activerecord.php, lines 46-3136
Inheritance Phpr_Extension » Phpr_Extensible » Phpr_Validatable » Db_Base » Db_WhereBase » Db_SqlBase » Db_ActiveRecord
Subclasses Db_File, Shop_BundleItemProduct, Shop_Category, Shop_CompanyInformation, Shop_Country, Shop_CountryState, Shop_CustomAttribute, Shop_CustomGroup, Shop_Customer, Shop_CustomerGroup, Shop_CustomerPaymentProfile, Shop_ExtraOption, Shop_Manufacturer, Shop_OptionMatrixRecord, Shop_Order, Shop_OrderItem, Shop_OrderStatus, Shop_OrderStatusLog, Shop_PaymentMethod, Shop_Product, Shop_ProductBundleItem, Shop_ProductProperty, Shop_ProductReview, Shop_ProductType, Shop_ShippingOption, Shop_ShippingParams
Author LemonStand eCommerce Inc.
Base class for LemonStand models. Db_ActiveRecord class is a base class for many other LemonStand classes, including Shop_Customer, Shop_Order, Cms_Page and others. The class has a number of methods which enable you to find and update records in the database.
Properties of this class subclasses depend on the table fields they represent. If a table had name field, a corresponding model class would have public $name property.
ActiveRecord uses the following constants for mapping data types:
  • db_varchar - varchar field
  • db_number - integer field
  • db_float - floating point number field
  • db_bool - boolean field
  • db_datetime - date/time field
  • db_date - date field
  • db_text - text field
ActiveRecord incapsulates all methods required for finding, creating, updating and deleting records in the database. Example of finding and updating a database record:
  $obj = new Shop_Customer();
  $customer = $obj->where('first_name=?', 'John')->where('last_name=?', 'Doe')->find();
  $customer->last_name = 'Smith';
  $customer->save();

Public properties

Property Type Description Defined By
auto_create_timestamps array a list of create timestamp columns. Db_ActiveRecord
auto_timestamps boolean determines whether create and update timestamp field should be set automatically. Db_ActiveRecord
auto_update_timestamps array a list of update timestamp columns. Db_ActiveRecord
belongs_to array contains a list of Belongs To Many relations. Db_ActiveRecord
calculated_columns array contains a list of calculated columns. Db_ActiveRecord
custom_columns array contains a list of custom fields definition. Db_ActiveRecord
fetched array contains an associative array of table column values fetched from the database. Db_ActiveRecord
has_and_belongs_to_many array contains a list of Has and Belongs To Many relations. Db_ActiveRecord
has_many array contains a list of Has Many relations. Db_ActiveRecord
has_one array contains a list of Has One relations. Db_ActiveRecord
primary_key string specifies a name of the table primary key. Db_ActiveRecord
validation Phpr_Validation contains the model's validation object. Db_ActiveRecord

Public methods

Show inherited methods.

Method Description Defined By
add_form_custom_area() adds a form custom area. Db_ActiveRecord
add_form_field() makes a column visible in forms. Db_ActiveRecord
add_form_partial() adds a custom form partial. Db_ActiveRecord
add_form_section() adds a form section. Db_ActiveRecord
after_create() called after a new object is saved to the database. Db_ActiveRecord
after_create_saved() called after a new object is saved to the database. Db_ActiveRecord
after_delete() called after an existing or new record is deleted from the database. Db_ActiveRecord
after_modify() called after an existing or new record was modified. Db_ActiveRecord
after_save() called after an existing or new record is created or updated in the database. Db_ActiveRecord
after_update() called after an existing record is updated in the database. Db_ActiveRecord
after_validation() triggered after the model column values are validated. Db_ActiveRecord
after_validation_on_create() triggered after a new model column values are validated. Db_ActiveRecord
after_validation_on_update() triggered after an existing model column values are validated. Db_ActiveRecord
before_create() called before a new object is saved to the database. Db_ActiveRecord
before_delete() called before a record is deleted from the database. Db_ActiveRecord
before_save() called before an existing or new record is created or updated in the database. Db_ActiveRecord
before_update() called before an existing record is updated in the database. Db_ActiveRecord
before_validation() triggered before the model column values are validated. Db_ActiveRecord
before_validation_on_create() triggered before a new model column values are validated. Db_ActiveRecord
before_validation_on_update() triggered before an existing model column values are validated. Db_ActiveRecord
collection() executes the find_all() method and returns a collection. Db_ActiveRecord
columnValue() alias for the displayField() method. Db_ActiveRecord
define_column() adds a column definition to the model. Db_ActiveRecord
define_form_fields() defines form fields. Db_ActiveRecord
define_multi_relation_column() adds column definition for has_and_belongs_to_many or has_many relation field. Db_ActiveRecord
define_relation_column() adds column definition for has_on or belongs_to relation field. Db_ActiveRecord
delete() deletes the record from the database. Db_ActiveRecord
delete_form_field() deletes a form field by its corresponding column name. Db_ActiveRecord
displayField() returns a formatted column value. The field should be defined with define_column(), Db_ActiveRecord
find() finds a record by its primary key value. Db_ActiveRecord
find_all() finds all records and returns the Db_DataCollection object, containing a list of models. Db_ActiveRecord
find_by() finds a record by a field value. Db_ActiveRecord
find_column_definition() finds a column definition by the column name. Db_ActiveRecord
find_form_field() finds a form field definition by its corresponding column name. Db_ActiveRecord
join() adds a table to the query with JOIN statement. Db_SqlBase
limit() allows to limit the result of the find_all() method with the specified number of records. Db_ActiveRecord
list_related_records_deferred() returns a list of relation objects, taking into account deferred relations. Db_ActiveRecord
order() allows to order the result of the find_all() method by a specific table column. Db_SqlBase
orWhere() adds OR statement to the where clause, allowing to to limit the result of the find() and find_all() methods with SQL filter. Db_WhereBase
paginate() allows to limit the result of the find_all() method with a single page of records. Db_ActiveRecord
requestRowCount() returns a number of rows which would be returned with find_all() method. Db_ActiveRecord
save() saves record to the database. Db_ActiveRecord
where() allows to limit the result of the find() and find_all() methods with SQL filter. Db_WhereBase

Protected methods

Method Description Defined By
define_columns() defines model columns. Db_ActiveRecord

Events

Event Description
core:onAfterDatabaseQuery Triggered before a SQL query is executed by the database.
core:onBeforeDatabaseConnect Triggered before database connection is established.
core:onBeforeDatabaseQuery Triggered before a SQL query is sent to the database.

Property details

auto_create_timestamps property

public array $auto_create_timestamps;
A list of create timestamp columns. Values of columns specified in this list are automatically set when the new model object is saved to the database By default created_at and created_on columns are considered as create timestamp columns.
Setting the create timestamp column values takes place only if auto_timestamps property value is TRUE.

auto_timestamps property

public boolean $auto_timestamps;
Determines whether create and update timestamp field should be set automatically. By default columns specified in auto_create_timestamps and auto_update_timestamps properties are set automatically when the model is saved. Assign FALSE value to this property to cancel this behavior.

auto_update_timestamps property

public array $auto_update_timestamps;
A list of update timestamp columns. Values of columns specified in this list are automatically set when an existing model object is saved to the database By default updated_at and updated_on columns are considered as update timestamp columns.
Setting the update timestamp column values takes place only if auto_timestamps property value is TRUE.

belongs_to property

public array $belongs_to;
Contains a list of Belongs To Many relations. Please read Creating data relations article for details.

calculated_columns property

public array $calculated_columns;
Contains a list of calculated columns. Use this property to define calculated columns in your models. Calculated columns do not exist in the data table. Instead they are calculated with SQL. Example:
public $calculated_columns = array( 
  'comment_num'=>'select count(*) from comments where post_id=post.id',
  'disk_file_name'=>array('sql'=>'files.file_create_date', 'join'=>array('files'=>'files.post_id=post.id'), 'type'=>db_date)
);
Defined calculated columns can be accessed as a regular class property:
$comment_num = $obj->comment_num;

custom_columns property

public array $custom_columns;
Contains a list of custom fields definition. Use this field to define custom columns in your models. Custom columns do not exist in the database and their values a are evaluated with special model methods when the model is loaded from the database. Each custom column should have a corresponding method in the model class. Example:
public $custom_columns = array('record_status'=>db_number, 'record_css_class'=>db_text);
This example the model to have two public methods for evaluating the column values:
public function eval_record_status() 
{
  return 1;
}

public function eval_record_css_class() 
{
  return $this->deleted ? 'deleted' : 'normal';
}
Defined custom fields can be accessed as a regular class property:
$record_status = $obj->record_status;

fetched property

public array $fetched;
Contains an associative array of table column values fetched from the database. You can use this field to compare original values with new values before the model is saved to the database.

has_and_belongs_to_many property

public array $has_and_belongs_to_many;
Contains a list of Has and Belongs To Many relations. Please read Creating data relations article for details.

has_many property

public array $has_many;
Contains a list of Has Many relations. Please read Creating data relations article for details.

has_one property

public array $has_one;
Contains a list of Has One relations. Please read Creating data relations article for details.

primary_key property

public string $primary_key;
Specifies a name of the table primary key. Default primary key name is id. Override this property in a model if its table has primary key with another name.

validation property

public Phpr_Validation $validation;
Contains the model's validation object. This model uses this method during the validation process.

Method details

add_form_custom_area() method

public Db_FormCustomArea add_form_custom_area(string $id, string $location=NULL)
$id string specifies an area identifier
$location string optional path of a directory containing the form area partial.
{return} Db_FormCustomArea returns the form custom area object.
Adds a form custom area. Form areas can contain arbitrary HTML markup. Form area contents should be defined in a partial with name _form_area_name.htm in the controller's views directory, where id is an area identifier specified in the method parameter. The optional $location parameter allows to specify a path of a directory containing the partial.

add_form_field() method

public Db_FormFieldDefinition add_form_field(string $dbName, $side $side='full')
$dbName string specifies a column database name or a calculated column name
$side $side specifies a side of the form the column should appear. Supported values: left, right, full
{return} Db_FormFieldDefinition returns the form field definition object.
Makes a column visible in forms. The column should be defined with define_column(), define_relation_column() or define_multi_relation_column() method before this method is called. The method returns the form field definition object which can be used for further configuration of the field. Example:
$this->add_form_field('author_name', 'left');

add_form_partial() method

public Db_FormPartial add_form_partial(string $path)
$path string specifies an absolute path to the partial file.
{return} Db_FormPartial returns the form partial object.
Adds a custom form partial. Form partials can contain arbitrary HTML markup. Example:
$this->add_form_partial(PATH_APP.'/modules/mymodule/partials/_form_partial.htm');

add_form_section() method

public Db_FormSection add_form_section(string $description, string $title=NULL, string $html_id=NULL)
$description string specifies a section description
$title string specifies a section title, optional
$html_id string specifies an id for the html element the form section will be rendered in on the form, optional
{return} Db_FormSection returns the form section object.
Adds a form section. Form sections allow to separate form space with a title and description text.

after_create() method

public void after_create()
Called after a new object is saved to the database. Override this method in your model classes if you need to perform any operations after the record is created in the database. When this method is called, object relations are not saved to the database yet.

after_create_saved() method

public void after_create_saved()
Called after a new object is saved to the database. Override this method in your model classes if you need to perform any operations after the record is created in the database. When this method is called, object relations are already saved to the database.

after_delete() method

public void after_delete()
Called after an existing or new record is deleted from the database. Override this method in your model classes if you need to perform any operations after the record is deleted from the database.

after_modify() method

public void after_modify(string $operation, string $deferred_session_key)
$operation string specifies the operation type. Possible values are: created, updated, deleted
$deferred_session_key string specifies the deferred session key passed to the save() method.
Called after an existing or new record was modified. Override this method in your model classes if you need to perform any operations after the record is modified.

after_save() method

public void after_save()
Called after an existing or new record is created or updated in the database. Override this method in your model classes if you need to perform any operations after the record is saved to the database.

after_update() method

public void after_update()
Called after an existing record is updated in the database. Override this method in your model classes if you need to perform any operations after the record is updated in the database.

after_validation() method

public void after_validation(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Triggered after the model column values are validated. Override this method in your model classes if you need to perform any operations after the model is validated.

after_validation_on_create() method

public void after_validation_on_create(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Triggered after a new model column values are validated. Override this method in your model classes if you need to perform any operations after a new model is validated.

after_validation_on_update() method

public void after_validation_on_update(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Triggered after an existing model column values are validated. Override this method in your model classes if you need to perform any operations after an existing model is validated.

before_create() method

public void before_create(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Called before a new object is saved to the database. Override this method in your model classes if you need to perform any operations before the record is created in the database.

before_delete() method

public void before_delete(integer $id=NULL)
$id integer specifies the record primary key value.
Called before a record is deleted from the database. Override this method in your model classes if you need to perform any operations before the record is deleted from the database. Usually this method is used for checking whether the object can be deleted. You can throw an exception in the handler to stop the operation. The following example demonstrates a typical usage of the method:
public function before_delete($id=null) 
{
  if ($order_num = $this->orders->count) // Load the number of customer orders from the relation
    throw new Phpr_ApplicationException("Error deleting customer. There are $order_num order(s) 
      belonging to this customer.");
}

before_save() method

public void before_save(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Called before an existing or new record is created or updated in the database. Override this method in your model classes if you need to perform any operations before the record is saved to the database.

before_update() method

public void before_update(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Called before an existing record is updated in the database. Override this method in your model classes if you need to perform any operations before the record is updated in the database.

before_validation() method

public void before_validation(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Triggered before the model column values are validated. Override this method in your model classes if you need to perform any operations before the model is validated.

before_validation_on_create() method

public void before_validation_on_create(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Triggered before a new model column values are validated. Override this method in your model classes if you need to perform any operations before a new model is validated.

before_validation_on_update() method

public void before_validation_on_update(string $deferred_session_key=NULL)
$deferred_session_key string specifies the deferred session key passed to the save() method.
Triggered before an existing model column values are validated. Override this method in your model classes if you need to perform any operations before an existing model is validated.

collection() method

public Db_DataCollection collection()
{return} Db_DataCollection returns a collection
Executes the find_all() method and returns a collection. This method simplifies front-end coding.

columnValue() method

public string columnValue(string $dbName)
$dbName string specifies the column name.
{return} string returns the formatted column value.
Alias for the displayField() method

define_column() method

public Db_ColumnDefinition define_column(string $dbName, string $displayName)
$dbName string specifies a column database name, a calculated column name, or a relation name.
$displayName string specifies a name to display in lists and forms.
{return} Db_ColumnDefinition returns the column definition object.
Adds a column definition to the model. Column definitions determine column labels, validation rules and other properties. The method returns column definition object object which you can use to configure the column presentation and validation parameters.

define_form_fields() method

public void define_form_fields(string $context=NULL)
$context string specifies the execution context.
Defines form fields. Override this method to define the model's form fields. All column which you add to the form should be defined with define_columns() method. Use add_form_field(), add_form_custom_area(), add_form_partial(), and add_form_section() methods inside this method. Example:
public function define_form_fields($context = null)
{
  $this->add_form_field('author_name', 'left');
  $this->add_form_field('author_email', 'right');
}

See Also

define_multi_relation_column() method

public Db_ColumnDefinition define_multi_relation_column(string $columnName, string $relationName, string $displayName, string $valueExpression)
$columnName string specifies a column name. Use any unique sql-compatible name.
$relationName string specifies a relation name (should be declared as has_and_belongs_to_many or has_many)
$displayName string specifies a name to display in lists and forms
$valueExpression string specifies SQL expression for evaluating the relation display value used in lists and forms. Use '@' symbol to indicate a joined table: concat(@first_name, ' ', @last_name).
{return} Db_ColumnDefinition returns the column definition object.
Adds column definition for has_and_belongs_to_many or has_many relation field. You should define columns for a relation field if you want the field to be displayed in lists or forms. The method returns a column definition object which you can use to configure the column presentation and validation parameters. Example:
public $has_and_belongs_to_many = array(
  'categories'=>array('class_name'=>'Blog_Category', 'join_table'=>'blog_posts_categories', 'order'=>'name')
);

...

public function define_columns($context = null)
{
  $this->define_multi_relation_column('categories', 'categories', 'Categories', '@name');
  ...
}

define_relation_column() method

public Db_ColumnDefinition define_relation_column(string $columnName, string $relationName, string $displayName, string $type, string $valueExpression)
$columnName string specifies the column name. Use any unique sql-compatible name.
$relationName string specifies the relation name (should be declared as has_many, has_and_belongs_to_many, belongs_to)
$displayName string specifies a name to display in lists and forms
$type string specifies a display value type (see db_xxx constants in the description of Db_ActiveRecord class)
$valueExpression string specifies SQL expression for evaluating the relation display value used in lists and forms. Use '@' symbol to indicate a joined table: concat(@first_name, ' ', @last_name).
{return} Db_ColumnDefinition returns the column definition object.
Adds column definition for has_on or belongs_to relation field. You should define columns for a relation field if you want the field to be displayed in lists or forms. The method returns column definition object object which you can use to configure the column presentation and validation parameters. Example:
public $belongs_to = array(
  'post'=>array('class_name'=>'Blog_Post', 'foreign_key'=>'post_id')
);

...

public function define_columns($context = null)
{
  $this->define_relation_column('post', 'post', 'Post', db_varchar, '@title');
  ...
}

delete() method

public void delete(integer $id=NULL)
$id integer specifies the record identifier. If the identifier is not provided, deletes the current record.
Deletes the record from the database.

delete_form_field() method

public boolean delete_form_field(string $dbName)
$dbName string specifies the column name.
{return} boolean returns TRUE if the field has been found and deleted. Returns FALSE otherwise.
Deletes a form field by its corresponding column name. This method can be used for removing a form field from an existing model before its form is rendered.

displayField() method

public string displayField(string $dbName, string $media='form')
$dbName string specifies the column name.
$media string specifies a media - a list or a form. Text values could be truncated for the list media.
{return} string returns the formatted column value.
Returns a formatted column value. The field should be defined with define_column(), define_relation_column() or define_multi_relation_column() method.
For relation fields the method uses relation data loaded from database with the model data instead of issuing another SQL query. It makes this method efficient in record lists.
By default datetime fields are converted to GMT during saving and displayField() returns value converted back to a time zone specified in TIMEZONE parameter in the configuration file (config.php). You can cancel this behavior by calling dateAsIs() of the column definition object.

find() method

public Db_ActiveRecord find(integer $id=NULL, array $include=array(), string $form_context=NULL)
$id integer specifies the primary key value.
$include array this parameter is reserved.
$form_context string allows to set the form execution context for the loaded records.
{return} Db_ActiveRecord returns a model object corresponding to the found record or NULL.
Finds a record by its primary key value. Note that if the primary key value passed to the method is NULL, the method returns the first record from the result set.

find_all() method

public Db_DataCollection find_all(integer $id=NULL, array $include=array(), string $form_context=NULL)
$id integer specifies the primary key value.
$include array this parameter is reserved.
$form_context string allows to set the form execution context for the loaded records.
{return} Db_DataCollection returns a collection of found records.
Finds all records and returns the Db_DataCollection object, containing a list of models.

find_by() method

public Db_ActiveRecord find_by(string $field, mixed $value, array $include=array())
$field string specifies the database field name.
$value mixed specifies the field value to find.
$include array this parameter is reserved.
{return} Db_ActiveRecord returns the model object corresponding to the found record or NULL.
Finds a record by a field value. There is a more usable magic method find_by_[column_name], where column_name is any database column name. Example:
$usa = Shop_Country::create()->find_by_code('US');

find_column_definition() method

public Db_ColumnDefinition find_column_definition(string $columnName)
$columnName string specifies the column name.
{return} Db_ColumnDefinition returns the column definition object or NULL if the column was not found in the model.
Finds a column definition by the column name. Columns are defined in define_columns() method.

find_form_field() method

public Db_FormFieldDefinition find_form_field(string $dbName)
$dbName string specifies the column name.
{return} Db_FormFieldDefinition returns the form field definition object or NULL if the field was not found.
Finds a form field definition by its corresponding column name. The form field should be defined with define_form_field() method. This method can be used for configuring a form field in an existing model before its form is rendered.

join() method

public Db_ActiveRecord join(string $table_name, string $conditions, string $columns='', string $type='left')
$table_name string specifies the table name to join.
$conditions string specifies the JOIN conditions (ON statement).
$columns string specifies a list of columns to include to the result set. This parameter is ignored in ActiveRecord.
$type string specifies the join type - left, inner, left outer, full outer.
{return} Db_ActiveRecord returns the configured model object.
Adds a table to the query with JOIN statement. The following code example loads all manufacturers which have products with name "T-shirt".
$obj = new Shop_Manufacturer();
$obj->join('shop_products', 'shop_products.manufacturer_id = shop_manufacturers.id');
$obj->where('shop_products.name=?', 'T-shirt');
$manufacturers = $obj->find_all();

limit() method

public Db_ActiveRecord limit(integer $count=NULL, integer $offset=NULL)
$count integer number of records to return.
$offset integer zero-based offset of the first returned record.
{return} Db_ActiveRecord returns the model object.
Allows to limit the result of the find_all() method with the specified number of records. The following example loads 10 newest orders from the database.
$orders = Shop_Order::create()->order('id desc')->limit(10);

list_related_records_deferred() method

public Db_DataCollection list_related_records_deferred(string $name, string $deferred_session_key)
$name string specifies the relation name.
$deferred_session_key string specifies deferred session key.
{return} Db_DataCollection returns the data collection object.
Returns a list of relation objects, taking into account deferred relations. Use this method to obtain a list of relation records, before the record is saved to the database.

order() method

public Db_ActiveRecord order(string $spec)
$spec string specifies the SQL order clause.
{return} Db_ActiveRecord returns the model object.
Allows to order the result of the find_all() method by a specific table column. The following example loads 10 newest orders from the database, ordered by identifier.
$orders = Shop_Order::create()->order('id desc')->limit(10);

orWhere() method

public Db_ActiveRecord orWhere()
{return} Db_ActiveRecord
Adds OR statement to the where clause, allowing to to limit the result of the find() and find_all() methods with SQL filter. Pass a SQL WHERE string to the parameter:
$order->where('customer_id is null')->orWhere('customer_id=4')->find_all();
or use the question mark as a data placeholder to pass a parameter value. Parameter values are automatically escaped (sanitized).
$orders = $order->orWhere('customer_id=?', 4)->find_all();

paginate() method

public Phpr_Pagination paginate(integer $page_index, integer $records_per_page)
$page_index integer specifies a zero-based page index.
$records_per_page integer specifies the number of records the page should contain.
{return} Phpr_Pagination returns the pagination object.
Allows to limit the result of the find_all() method with a single page of records. Call this method before the find_all() method call.
$pagination = $products->paginate(0, 10);

See Also

requestRowCount() method

public integer requestRowCount()
{return} integer returns the number of rows.
Returns a number of rows which would be returned with find_all() method. Use this method to obtain the number of records which is going to be returned by a subsequent find_all() method call.

save() method

public Db_ActiveRecord save(array $values=NULL, string $deferred_session_key=NULL)
$values array
$deferred_session_key string optional deferred session key.
{return} Db_ActiveRecord returns the saved model object
Saves record to the database. Depending on whether the model was created or loaded from the database the method creates or updates a corresponding table record. The optional $values array can be used to set the record field values.
$customer = Shop_Customer::create()->find(23);
$customer->save(array('first_name'=>'john'));
Alternatively you can set the column values directly:
$customer = Shop_Customer::create()->find(23);
$customer->first_name = 'john';
$customer->save();

where() method

public Db_ActiveRecord where()
{return} Db_ActiveRecord
Allows to limit the result of the find() and find_all() methods with SQL filter. Pass a SQL WHERE string to the parameter:
$order->where('customer_id is not null')->find_all();
or use the question mark as a data placeholder to pass a parameter value. Parameter values are automatically escaped (sanitized).
$orders = $order->where('customer_id=?', 4)->find_all();

define_columns() method

protected void define_columns(string $context=NULL)
$context string specifies the execution context.
Defines model columns. Override this method to define columns, references and form fields in your models. By defining columns you inform the framework which fields from the database table we are going to use in lists and forms, and what titles these fields should have. Columns are objects of Db_ColumnDefinition class, which has a number of properties determining how the column is displayed and validated. You can call model's define_column(), define_relation_column() and define_multi_relation_column() methods inside this method. Example:
public function define_columns($context = null)
{
  $this->define_column('title', 'Title')->order('asc')->validation()->fn('trim');
  $this->define_multi_relation_column('categories', 'categories', 'Categories', '@name');
}

See Also