|
Agile Toolkit
4.2
Agile Toolkit is a powerful web development framework. Inspired by GUI Applications development
|
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 | |
Implementation of a Relational SQL-backed Model Model_Table allows you to take advantage of relational SQL database without neglecting powerful functionality of your RDBMS. On top of basic load/save/delete operations, you can pefrorm multi-row operations, traverse relations, or use SQL expressions The $table property of Model_Table always contains the primary table. The $this->id will always correspond with ID field of that table and when inserting record will always be placed inside primary table first. Use: class Model_User extends Model_Table { public $table='user'; function init(){ parent::init(); $this->addField('name'); $this->addField('email'); } } // Creates new user, but looks for email duplicates before inserting $user=$this->add('Model_User'); $user->loadBy('email',$email); if(!$user->loaded()){ $user->unload(); return $user->set('email',$email)->save(); }else throw $user->exception('User with such email already exists'); See http://agiletoolkit.org/about/license
| __construct | ( | ) |
Initialization of ID field, which must always be defined
| __destruct | ( | ) |
Always call parent if you redefine this
Reimplemented from AbstractObject.
| _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
| debug | ( | ) |
Turns on debugging mode for this model. All database operations will be outputed
| 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.
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
| getTitleField | ( | ) |
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
| isInstanceLoaded | ( | ) |
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
| 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
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
| ref | ( | $ | name, |
| $ | load = null |
||
| ) |
| reload | ( | ) |
Unloads then loads current record back. Use this if you have added new fields
| save | ( | ) |
Save model into database and load it back. If for some reason it won't load, whole operation is undone
| saveAndUnload | ( | ) |
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
| titleQuery | ( | ) |
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
| tryLoadAny | ( | ) |
Try to load a matching record for the model. Will not raise exception if no records are found
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.
$_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' |