Agile Toolkit  4.2
Agile Toolkit is a powerful web development framework. Inspired by GUI Applications development
Model_Table Class Reference
Inheritance diagram for Model_Table:
Model AbstractModel AbstractObject

Public Member Functions

 __construct ()
 init ()
 addField ($name, $actual_field=null)
 exception ()
 initQuery ()
 _dsql ()
 __clone ()
 dsql ()
 debug ()
 getActualFields ($group=undefined)
 setActualFields (array $fields)
 selectQuery ($fields=null)
 getTitleField ()
 titleQuery ()
 addExpression ($name, $expression=null)
 join ($foreign_table, $master_field=null, $join_kind=null, $_foreign_alias=null, $relation=null)
 leftJoin ($foreign_table, $master_field=null, $join_kind=null, $_foreign_alias=null, $relation=null)
 addReference ($name)
 hasOne ($model, $our_field=null, $display_field=null)
 hasMany ($model, $their_field=null, $our_field=null)
 ref ($name, $load=null)
 refSQL ($name, $table_alias=null)
 getRef ($name, $load=null)
 addCondition ($field, $cond=undefined, $value=undefined)
 setOrder ($field, $desc=false, $_compat_desc=null)
 setMasterField ($field, $value)
 rewind ()
 next ()
 current ()
 key ()
 valid ()
 getRows ($fields=null)
 count ()
 sum ($field)
 isInstanceLoaded ()
 loadAny ()
 tryLoadAny ()
 tryLoad ($id)
 load ($id)
 loadBy ($field, $cond=undefined, $value=undefined)
 tryLoadBy ($field, $cond=undefined, $value=undefined)
 getBy ($field, $cond=undefined, $value=undefined)
 reload ()
 loadData ($id=null)
 saveAndUnload ()
 saveLater ()
 __destruct ()
 saveAs ($model)
 save ()
 update ($data=array())
 unload ()
 delete ($id=null)
 deleteAll ()

Data Fields

 $id_field = 'id'
 $title_field = 'name'
 $table_alias = null
 $entity_code = null
 $relations = array()
 $debug = false
 $actual_fields = false

Protected Member Functions

 _load ($id, $ignore_missing=false)

Protected Attributes

 $dsql
 $_iterating = false

Detailed Description


Constructor & Destructor Documentation

Initialization of ID field, which must always be defined

Always call parent if you redefine this

Reimplemented from AbstractObject.


Member Function Documentation

__clone ( )

Reimplemented from Model.

_dsql ( )

Use this instead of accessing dsql directly. This will initialize $dsql property if it does not exist yet

_load ( id,
ignore_missing = false 
) [protected]

Internal loading funciton. Do not use. OK to override.

addCondition ( field,
cond = undefined,
value = undefined 
)

Adds a "WHERE" condition, but tries to be smart about where and how the field is defined

addExpression ( name,
expression = null 
)

Adds and returns SQL-calculated expression as a read-only field. See Field_Expression class.

addField ( name,
actual_field = null 
)
addReference ( name)

Adds a sub-query and manyToOne reference

count ( )

Returs dynamic query selecting number of entries in the database

current ( )

Reimplemented from Model.

debug ( )

Turns on debugging mode for this model. All database operations will be outputed

delete ( id = null)

Deletes record matching the ID

Reimplemented from Model.

deleteAll ( )

Deletes all records matching this model. Use with caution.

dsql ( )

Produces a close of Dynamic SQL object configured with table, conditions and joins of this model. Use for statements you are going to execute manually.

exception ( )

exception() will automatically add information about current model and will allow to turn on "debug" mode

getActualFields ( group = undefined)

Returs list of fields which belong to specific group. You can add fields into groups when you define them and it can be used by the front-end to determine which fields needs to be displayed.

If no group is specified, then all non-system fields are displayed for backwards compatibility.

getBy ( field,
cond = undefined,
value = undefined 
)

Loads data record and return array of that data. Will not affect currently loaded record.

getRef ( name,
load = null 
)

- return model referenced by a field. Use model name for one-to-many relations

getRows ( fields = null)

Loads all matching data into array of hashes

Returns field which should be used as a title

hasMany ( model,
their_field = null,
our_field = null 
)

Defines many to one association

hasOne ( model,
our_field = null,
display_field = null 
)

Defines one to many association

init ( )

Initialize object. Always call parent

This method is called for initialization

Reimplemented from Model.

initQuery ( )

Initializes base query for this model. http://agiletoolkit.org/doc/modeltable/dsql

same as loaded() - returns if any record is currently loaded.

join ( foreign_table,
master_field = null,
join_kind = null,
_foreign_alias = null,
relation = null 
)

Constructs model from multiple tables. Queries will join tables, inserts, updates and deletes will be applied on both tables

key ( )

Reimplemented from Model.

leftJoin ( foreign_table,
master_field = null,
join_kind = null,
_foreign_alias = null,
relation = null 
)

Creates weak join between tables. The foreign table may be absent and will not be automatically deleted

load ( id)

Loads record specified by ID. If omitted will load first matching record

Reimplemented from Model.

loadAny ( )

Loads the first matching record from the model

loadBy ( field,
cond = undefined,
value = undefined 
)

Similar to loadAny() but will apply condition before loading. Condition is temporary. Fails if record is not loaded.

loadData ( id = null)

Backward-compatible. Will attempt to load but will not fail

next ( )

Reimplemented from Model.

ref ( name,
load = null 
)

Traverses references. Use field name for hasOne() relations. Use model name for hasMany()

refSQL ( name,
table_alias = null 
)

Returns Model with SQL join usable for subqueries.

reload ( )

Unloads then loads current record back. Use this if you have added new fields

rewind ( )

Reimplemented from Model.

save ( )

Save model into database and load it back. If for some reason it won't load, whole operation is undone

Save model into database and try to load it back as a new model of specified class. Instance of new class is returned

saveAs ( model)
saveLater ( )

Will save model later, when it's being destructed by Garbage Collector

selectQuery ( fields = null)

Completes initialization of dsql() by adding fields and expressions.

setActualFields ( array $  fields)

Default set of fields which will be included into further queries

setMasterField ( field,
value 
)

use two-argument addCondition. Always keep $field equals to $value for queries and new data

setOrder ( field,
desc = false,
_compat_desc = null 
)

Sets an order on the field. Field must be properly defined

sum ( field)

Returs dynamic query selecting sum of particular field

Returns query which selects title field

tryLoad ( id)

Try to load a record by specified ID. Will not raise exception if record is not fourd

Try to load a matching record for the model. Will not raise exception if no records are found

tryLoadBy ( field,
cond = undefined,
value = undefined 
)

Attempt to load using a specified condition, but will not fail if such record is not found

unload ( )

forget currently loaded record and it's ID. Will not affect database

Reimplemented from Model.

update ( data = array())

. Use set() then save().

valid ( )

Reimplemented from Model.


Field Documentation

$_iterating = false [protected]
$actual_fields = false
$debug = false
$dsql [protected]

Master DSQL record which will be cloned by other operations. For low level use only. Use $this->dsql() when in doubt.

$entity_code = null
$id_field = 'id'

The actual ID field of the table might now always be "id"

$relations = array()
$table_alias = null

If you wish that alias is used for the table when selected, you can define it here. This will help to keep SQL syntax shorter, but will not impact functionality

$title_field = 'name'

The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables Enumerations