Model Class Reference

Inheritance diagram for Model:

Overloadable Object Object AppModel AppModel AclNode AcoAction Permission AclNode AcoAction Permission Aco Aro Aco Aro List of all members.

Public Member Functions

 __collectForeignKeys ($type= 'belongsTo')
 __construct ($id=false, $table=null, $ds=null)
 __constructLinkedModel ($assoc, $className=null)
 __createLinks ()
 __filterResults ($results, $primary=true)
 __generateAssociation ($type)
 __save ($data, $options)
 __saveMulti ($joined, $id)
 __sleep ()
 __wakeup ()
 _clearCache ($type=null)
 _deleteDependent ($id, $cascade)
 _deleteLinks ($id)
 _findCount ($state, $query, $results=array())
 _findFirst ($state, $query, $results=array())
 _findList ($state, $query, $results=array())
 _findNeighbors ($state, $query, $results=array())
 _findThreaded ($state, $query, $results=array())
 _prepareUpdateFields ($data)
 afterDelete ()
 afterFind ($results, $primary=false)
 afterSave ($created)
 beforeDelete ($cascade=true)
 beforeFind ($queryData)
 beforeSave ($options=array())
 beforeValidate ($options=array())
 bind ($model, $options=array(), $permanent=true)
 bindModel ($params, $reset=true)
 call__ ($method, $params)
 create ($data=array(), $filterKey=false)
 deconstruct ($field, $data)
 del ($id=null, $cascade=true)
 delete ($id=null, $cascade=true)
 deleteAll ($conditions, $cascade=true, $callbacks=false)
 escapeField ($field=null, $alias=null)
 exists ($reset=false)
 field ($name, $conditions=null, $order=null)
 find ($conditions=null, $fields=array(), $order=null, $recursive=null)
 findAll ($conditions=null, $fields=null, $order=null, $limit=null, $page=1, $recursive=null)
 findAllThreaded ($conditions=null, $fields=null, $order=null)
 findCount ($conditions=null, $recursive=0)
 findNeighbours ($conditions=null, $field, $value)
 getAffectedRows ()
 getAssociated ($type=null)
 getColumnType ($column)
 getColumnTypes ()
getDataSource ()
 getDisplayField ()
 getID ($list=0)
 getInsertID ()
 getLastInsertID ()
 getNumRows ()
 hasAny ($conditions=null)
 hasField ($name)
 invalidate ($field, $value=true)
 invalidFields ($options=array())
 isForeignKey ($field)
 isUnique ($fields, $or=true)
 joinModel ($assoc, $keys=array())
 onError ()
 query ()
 read ($fields=null, $id=null)
 remove ($id=null, $cascade=true)
 resetAssociations ()
 save ($data=null, $validate=true, $fieldList=array())
 saveAll ($data=null, $options=array())
 saveField ($name, $value, $validate=false)
 schema ($field=false)
 set ($one, $two=null)
 setDataSource ($dataSource=null)
 setInsertID ($id)
 setSource ($tableName)
 unbindModel ($params, $reset=true)
 updateAll ($fields, $conditions=true)
 updateCounterCache ($keys=array(), $created=false)
 validates ($options=array())

Public Attributes

 $__affectedRows = null
 $__associationKeys
 $__associations = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany')
 $__backAssociation = array()
 $__exists = null
 $__insertID = null
 $__numRows = null
 $_findMethods
 $_schema = null
 $actsAs = null
 $alias = null
 $Behaviors = null
 $belongsTo = array()
 $cacheQueries = false
 $cacheSources = true
 $data = array()
 $displayField = null
 $findQueryType = null
 $hasAndBelongsToMany = array()
 $hasMany = array()
 $hasOne = array()
 $id = false
 $logTransactions = false
 $name = null
 $order = null
 $primaryKey = null
 $recursive = 1
 $table = false
 $tablePrefix = null
 $tableToModel = array()
 $transactional = false
 $useDbConfig = 'default'
 $useTable = null
 $validate = array()
 $validationErrors = array()
 $whitelist = array()

Detailed Description

Definition at line 43 of file model.php.


Constructor & Destructor Documentation

Model::__construct ( id = false,
table = null,
ds = null 
)

Constructor. Binds the model's database table to the object.

Parameters:
integer $id Set this ID for this model on startup
string $table Name of database table to use.
object $ds DataSource connection object.

Definition at line 340 of file model.php.

References $alias, $id, $name, $table, __construct(), __createLinks(), ClassRegistry::addObject(), hasField(), Set::merge(), name(), setDataSource(), setSource(), and tableize().


Member Function Documentation

Model::__collectForeignKeys ( type = 'belongsTo'  ) 

Collects foreign keys from associations.

Returns:
array private

Definition at line 1860 of file model.php.

Referenced by del().

Model::__constructLinkedModel ( assoc,
className = null 
)

Private helper method to create associated models of a given class.

Parameters:
string $assoc Association name
string $className Class name
Deprecated:
$this->$className use $this->$assoc instead. $assoc is the 'key' in the associations array; examples: var $hasMany = array('Assoc' => array('className' => 'ModelName')); usage: $this->Assoc->modelMethods();
var $hasMany = array('ModelName'); usage: $this->ModelName->modelMethods();
Returns:
void private

Definition at line 633 of file model.php.

References ClassRegistry::init(), and name().

Referenced by __createLinks(), __generateAssociation(), and bind().

Model::__createLinks (  ) 

Create a set of associations.

Returns:
void private

Definition at line 573 of file model.php.

References __constructLinkedModel(), and __generateAssociation().

Referenced by __construct(), and bindModel().

Model::__filterResults ( results,
primary = true 
)

Passes query results through model and behavior afterFilter() methods.

Parameters:
array Results to filter
boolean $primary If this is the primary model results (results from model where the find operation was performed)
Returns:
array Set of filtered results private

Definition at line 2231 of file model.php.

References afterFind().

Referenced by find().

Model::__generateAssociation ( type  ) 

Build an array-based association from string.

Parameters:
string $type 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'
Returns:
void private

Definition at line 657 of file model.php.

References $data, __constructLinkedModel(), camelize(), ClassRegistry::isKeySet(), name(), schema(), singularize(), and underscore().

Referenced by __createLinks(), and bind().

Model::__save ( data,
options 
)

Private helper method used by saveAll.

Returns:
boolean Success private
See also:
Model::saveAll()

Definition at line 1653 of file model.php.

References create(), save(), and validates().

Referenced by saveAll().

Model::__saveMulti ( joined,
id 
)

Saves model hasAndBelongsToMany data to the database.

Parameters:
array $joined Data to save
mixed $id ID of record in this model private

Definition at line 1295 of file model.php.

References $data, $id, Set::extract(), getColumnType(), ConnectionManager::getDataSource(), joinModel(), name(), and String::uuid().

Referenced by save().

Model::__sleep (  ) 

Called when serializing a model.

Returns:
array Set of object variable names this model has private

Definition at line 2843 of file model.php.

Model::__wakeup (  ) 

Called when de-serializing a model.

private

Todo:

Definition at line 2853 of file model.php.

Model::_clearCache ( type = null  ) 

Private method. Clears cache for this model.

Parameters:
string $type If null this deletes cached views if Cache.check is true Will be used to allow deleting query cache also
Returns:
boolean true on delete protected
Todo:

Definition at line 2816 of file model.php.

References clearCache(), pluralize(), Configure::read(), and underscore().

Referenced by del(), and save().

Model::_deleteDependent ( id,
cascade 
)

Cascades model deletes through associated hasMany and hasOne child records.

Parameters:
string $id ID of record that was deleted
boolean $cascade Set to true to delete records that depend on this record
Returns:
void protected

Definition at line 1752 of file model.php.

References escapeField().

Referenced by del(), and deleteAll().

Model::_deleteLinks ( id  ) 

Cascades model deletes through HABTM join keys.

Parameters:
string $id ID of record that was deleted
Returns:
void protected

Definition at line 1791 of file model.php.

References escapeField(), and ConnectionManager::getDataSource().

Referenced by del(), and deleteAll().

Model::_findCount ( state,
query,
results = array() 
)

Handles the before/after filter logic for find('count') operations. Only called by Model::find().

Parameters:
string $state Either "before" or "after"
array $query
array $data
Returns:
int The number of records found, or false protected
See also:
Model::find()

Definition at line 2040 of file model.php.

References ConnectionManager::getDataSource().

Model::_findFirst ( state,
query,
results = array() 
)

Handles the before/after filter logic for find('first') operations. Only called by Model::find().

Parameters:
string $state Either "before" or "after"
array $query
array $data
Returns:
array protected
See also:
Model::find()

Definition at line 2016 of file model.php.

References escapeField().

Model::_findList ( state,
query,
results = array() 
)

Handles the before/after filter logic for find('list') operations. Only called by Model::find().

Parameters:
string $state Either "before" or "after"
array $query
array $data
Returns:
array Key/value pairs of primary keys/display field values of all records found protected
See also:
Model::find()

Definition at line 2071 of file model.php.

References Set::combine(), and String::tokenize().

Model::_findNeighbors ( state,
query,
results = array() 
)

Detects the previous field's value, then uses logic to find the 'wrapping' rows and return them.

Parameters:
string $state Either "before" or "after"
mixed $query
array $results
Returns:
array protected

Definition at line 2129 of file model.php.

References Set::extract(), field(), find(), and id().

Model::_findThreaded ( state,
query,
results = array() 
)

In the event of ambiguous results returned (multiple top level results, with different parent_ids) top level results with different parent_ids to the first result will be dropped

Parameters:
mixed $state
mixed $query
array $results
Returns:
array Threaded results protected

Definition at line 2187 of file model.php.

References Set::extract().

Model::_prepareUpdateFields ( data  ) 

Helper method for Model::updateCounterCache(). Checks the fields to be updated for

Parameters:
array $data The fields of the record that will be updated
Returns:
array Returns updated foreign key values, along with an 'old' key containing the old values, or empty if no foreign keys are updated. protected

Definition at line 1439 of file model.php.

References $data, and find().

Referenced by save().

Model::afterDelete (  ) 

Called after every deletion operation.

public http://book.cakephp.org/view/686/afterDelete

Definition at line 2785 of file model.php.

Referenced by del().

Model::afterFind ( results,
primary = false 
)

Called after each find operation. Can be used to modify any results returned by find(). Return value should be the (modified) results.

Parameters:
mixed $results The results of the find operation
boolean $primary Whether this model is being queried directly (vs. being queried as an association)
Returns:
mixed Result of the find operation public http://book.cakephp.org/view/681/afterFind

Definition at line 2745 of file model.php.

Referenced by __filterResults().

Model::afterSave ( created  ) 

Called after each successful save operation.

Parameters:
boolean $created True if this save created a new record public http://book.cakephp.org/view/684/afterSave

Definition at line 2766 of file model.php.

Referenced by save().

Model::beforeDelete ( cascade = true  ) 

Called before every deletion operation.

Parameters:
boolean $cascade If true records that depend on this record will also be deleted
Returns:
boolean True if the operation should continue, false if it should abort public http://book.cakephp.org/view/685/beforeDelete

Definition at line 2776 of file model.php.

Referenced by del().

Model::beforeFind ( queryData  ) 

Called before each find operation. Return false if you want to halt the find call, otherwise return the (modified) query data.

Parameters:
array $queryData Data used to execute this query, i.e. conditions, order, etc.
Returns:
mixed true if the operation should continue, false if it should abort; or, modified $queryData to continue with new $queryData public http://book.cakephp.org/view/680/beforeFind

Definition at line 2732 of file model.php.

Referenced by find().

Model::beforeSave ( options = array()  ) 

Called before each save operation, after validation. Return a non-true result to halt the save.

Returns:
boolean True if the operation should continue, false if it should abort public http://book.cakephp.org/view/683/beforeSave

Definition at line 2756 of file model.php.

Referenced by save().

Model::beforeValidate ( options = array()  ) 

Called during save operations, before validation. Please note that custom validation rules can be defined in $validate.

Returns:
boolean True if validate operation should continue, false to abort
Parameters:
$options array Options passed from model::save(), see $options of model::save(). public http://book.cakephp.org/view/682/beforeValidate

Definition at line 2796 of file model.php.

Referenced by invalidFields().

Model::bind ( model,
options = array(),
permanent = true 
)

Bind model associations on the fly.

If $permanent is true, association will not be reset to the originals defined in the model.

Parameters:
mixed $model A model or association name (string) or set of binding options (indexed by model name type)
array $options If $model is a string, this is the list of association properties with which $model will be bound
boolean $permanent Set to true to make the binding permanent
Returns:
void public
Todo:

Definition at line 462 of file model.php.

References $name, __constructLinkedModel(), and __generateAssociation().

Model::bindModel ( params,
reset = true 
)

Bind model associations on the fly.

If $reset is false, association will not be reset to the originals defined in the model

Example: Add a new hasOne binding to the Profile model not defined in the model source code: $this->User->bindModel( array('hasOne' => array('Profile')) );

Parameters:
array $params Set of bindings (indexed by binding type)
boolean $reset Set to false to make the binding permanent
Returns:
boolean Success public http://book.cakephp.org/view/86/Creating-and-Destroying-Associations-on-the-Fly

Definition at line 515 of file model.php.

References __createLinks().

Model::call__ ( method,
params 
)

Handles custom method calls, like findBy<field> for DB models, and custom RPC calls for remote data sources.

Parameters:
string $method Name of method to call.
array $params Parameters for the method.
Returns:
mixed Whatever is returned by called method protected

Definition at line 434 of file model.php.

References ConnectionManager::getDataSource(), and resetAssociations().

Model::create ( data = array(),
filterKey = false 
)

Initializes the model for writing a new record, loading the default values for those fields that are not defined in $data. Especially helpful for saving data in loops.

Parameters:
mixed $data Optional data array to assign to the model after it is created. If null or false, schema data defaults are not merged.
boolean $filterKey If true, overwrites any primary key input with an empty value
Returns:
array The current Model::data; after merging $data and/or defaults from database public http://book.cakephp.org/view/75/Saving-Your-Data

Definition at line 996 of file model.php.

References $data, Set::filter(), schema(), and set().

Referenced by __save(), invalidFields(), save(), and saveField().

Model::deconstruct ( field,
data 
)

Deconstructs a complex data type (array or object) into a single field value.

Parameters:
string $field The name of the field to be deconstructed
mixed $data An array or object to be deconstructed into a field
Returns:
mixed The resulting data that should be assigned to a field public

Definition at line 821 of file model.php.

References $data, am(), getColumnType(), and ConnectionManager::getDataSource().

Referenced by set().

Model::del ( id = null,
cascade = true 
)

Removes record for given ID. If no ID is given, the current ID is used. Returns true on success.

Parameters:
mixed $id ID of record to delete
boolean $cascade Set to true to delete records that depend on this record
Returns:
boolean True on success public http://book.cakephp.org/view/690/del

Definition at line 1699 of file model.php.

References $id, __collectForeignKeys(), _clearCache(), _deleteDependent(), _deleteLinks(), afterDelete(), beforeDelete(), exists(), find(), ConnectionManager::getDataSource(), id(), and updateCounterCache().

Referenced by delete(), and remove().

Model::delete ( id = null,
cascade = true 
)

Alias for del().

Parameters:
mixed $id ID of record to delete
boolean $cascade Set to true to delete records that depend on this record
Returns:
boolean True on success public
See also:
Model::del()

Definition at line 1741 of file model.php.

References del().

Model::deleteAll ( conditions,
cascade = true,
callbacks = false 
)

Deletes multiple model records based on a set of conditions.

Parameters:
mixed $conditions Conditions to match
boolean $cascade Set to true to delete records that depend on this record
boolean $callbacks Run callbacks (not being used)
Returns:
boolean True on success, false on failure public http://book.cakephp.org/view/692/deleteAll

Definition at line 1817 of file model.php.

References _deleteDependent(), _deleteLinks(), Set::extract(), find(), ConnectionManager::getDataSource(), and id().

Model::escapeField ( field = null,
alias = null 
)

Escapes the field name and prepends the model name. Escaping is done according to the current database driver's rules.

Parameters:
string $field Field to escape (e.g: id)
string $alias Alias for the model (e.g: Post)
Returns:
string The name of the escaped field for this Model (i.e. id becomes `Post`.`id`). public

Definition at line 2535 of file model.php.

References $alias, ConnectionManager::getDataSource(), and name().

Referenced by _deleteDependent(), _deleteLinks(), _findFirst(), and updateCounterCache().

Model::exists ( reset = false  ) 

Returns true if a record with the currently set ID exists.

Parameters:
boolean $reset if true will force database query
Returns:
boolean True if such a record exists public

Definition at line 1877 of file model.php.

References find(), and getID().

Referenced by del(), invalidFields(), and save().

Model::field ( name,
conditions = null,
order = null 
)

Returns the contents of a single field given the supplied conditions, in the supplied order.

Parameters:
string $name Name of field to get
array $conditions SQL conditions (defaults to NULL)
string $order SQL ORDER BY fragment
Returns:
string field contents, or false if not found public http://book.cakephp.org/view/453/field

Definition at line 1060 of file model.php.

References $data, $name, $order, $recursive, and find().

Referenced by _findNeighbors(), findNeighbours(), getColumnTypes(), invalidFields(), and updateCounterCache().

Model::find ( conditions = null,
fields = array(),
order = null,
recursive = null 
)

Returns a result set array.

Also used to perform new-notation finds, where the first argument is type of find operation to perform (all / first / count / neighbors / list / threaded ), second parameter options for finding ( indexed array, including: 'conditions', 'limit', 'recursive', 'page', 'fields', 'offset', 'order')

Eg: find('all', array( 'conditions' => array('name' => 'Thomas Anderson'), 'fields' => array('name', 'email'), 'order' => 'field3 DESC', 'recursive' => 2, 'group' => 'type'));

Specifying 'fields' for new-notation 'list':

Parameters:
array $conditions SQL conditions array, or type of find operation (all / first / count / neighbors / list / threaded)
mixed $fields Either a single string of a field name, or an array of field names, or options for matching
string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
integer $recursive The number of levels deep to fetch associated records
Returns:
array Array of records public http://book.cakephp.org/view/449/find

Definition at line 1935 of file model.php.

References __filterResults(), beforeFind(), ConnectionManager::getDataSource(), getID(), group(), offset(), and resetAssociations().

Referenced by _findNeighbors(), _prepareUpdateFields(), del(), deleteAll(), exists(), field(), findAll(), findAllThreaded(), findCount(), findNeighbours(), hasAny(), isUnique(), read(), and updateCounterCache().

Model::findAll ( conditions = null,
fields = null,
order = null,
limit = null,
page = 1,
recursive = null 
)

Deprecated:
See also:
Model::find('all')

Definition at line 2859 of file model.php.

References find().

Model::findAllThreaded ( conditions = null,
fields = null,
order = null 
)

Deprecated:
See also:
Model::find('threaded')

Definition at line 2875 of file model.php.

References find().

Model::findCount ( conditions = null,
recursive = 0 
)

Deprecated:
See also:
Model::find('count')

Definition at line 2867 of file model.php.

References find().

Model::findNeighbours ( conditions = null,
field,
value 
)

Deprecated:
See also:
Model::find('neighbors')

Definition at line 2883 of file model.php.

References field(), and find().

Model::getAffectedRows (  ) 

Returns the number of rows affected by the last query.

Returns:
int Number of rows public

Definition at line 2623 of file model.php.

References ConnectionManager::getDataSource().

Model::getAssociated ( type = null  ) 

Gets all the models with which this model is associated.

Parameters:
string $type Only result associations of this type
Returns:
array Associations public

Definition at line 2673 of file model.php.

Referenced by saveAll(), and set().

Model::getColumnType ( column  ) 

Returns the column type of a column in the model.

Parameters:
string $column The name of the model column
Returns:
string Column type public

Definition at line 938 of file model.php.

References ConnectionManager::getDataSource(), and schema().

Referenced by __saveMulti(), deconstruct(), and save().

Model::getColumnTypes (  ) 

Returns an associative array of field names and column types.

Returns:
array Field types indexed by field name public

Definition at line 920 of file model.php.

References __(), a(), field(), and schema().

& Model::getDataSource (  ) 

Gets the DataSource to which this model is bound. Not safe for use with some versions of PHP4, because this class is overloaded.

Returns:
object A DataSource object public

Definition at line 2662 of file model.php.

References ConnectionManager::getDataSource().

Model::getDisplayField (  ) 

Returns the display field for this model.

Returns:
string The name of the display field for this Model (i.e. 'name', 'title'). public
Deprecated:

Definition at line 2524 of file model.php.

Model::getID ( list = 0  ) 

Returns the current record's ID

Parameters:
integer $list Index on which the composed ID is located
Returns:
mixed The ID of the current record, false if no ID public

Definition at line 2555 of file model.php.

References id().

Referenced by exists(), and find().

Model::getInsertID (  ) 

Returns the ID of the last record this model inserted.

Returns:
mixed Last inserted ID public

Definition at line 2595 of file model.php.

Referenced by getLastInsertID().

Model::getLastInsertID (  ) 

Returns the ID of the last record this model inserted.

Returns:
mixed Last inserted ID public

Definition at line 2586 of file model.php.

References getInsertID().

Model::getNumRows (  ) 

Returns the number of rows returned from the last query.

Returns:
int Number of rows public

Definition at line 2613 of file model.php.

References ConnectionManager::getDataSource().

Model::hasAny ( conditions = null  ) 

Returns true if a record that meets given conditions exists.

Parameters:
array $conditions SQL conditions array
Returns:
boolean True if such a record exists public

Definition at line 1903 of file model.php.

References find().

Model::hasField ( name  ) 

Returns true if the supplied field exists in the model's database table.

Parameters:
mixed $name Name of field to look for, or an array of names
Returns:
mixed If $name is a string, returns a boolean indicating whether the field exists. If $name is an array of field names, returns the first field that exists, or false if none exist. public

Definition at line 965 of file model.php.

References $name, and schema().

Referenced by __construct(), save(), and updateCounterCache().

Model::invalidate ( field,
value = true 
)

Marks a field as invalid, optionally setting the name of validation rule (in case of multiple validation for field) that was broken.

Parameters:
string $field The name of the field to invalidate
mixed $value Name of validation rule that was not failed, or validation message to be returned. If no validation key is provided, defaults to true. public

Definition at line 2495 of file model.php.

Referenced by invalidFields().

Model::invalidFields ( options = array()  ) 

Returns an array of fields that have failed validation.

Parameters:
string $options An optional array of custom options to be made available in the beforeValidate callback
Returns:
array Array of invalid fields public http://book.cakephp.org/view/410/Validating-Data-from-the-Controller

Definition at line 2344 of file model.php.

References $validate, $whitelist, __(), beforeValidate(), create(), Object::dispatchMethod(), exists(), false, field(), Validation::getInstance(), and invalidate().

Referenced by validates().

Model::isForeignKey ( field  ) 

Returns true if given field name is a foreign key in this model.

Parameters:
string $field Returns true if the input string ends in "_id"
Returns:
boolean True if the field is a foreign key listed in the belongsTo array. public

Definition at line 2508 of file model.php.

Model::isUnique ( fields,
or = true 
)

Returns false if any fields passed match any (by default, all if $or = false) of their matching values.

Parameters:
array $fields Field/value pairs to search (if no values specified, they are pulled from $this->data)
boolean $or If false, all fields specified must match in order for a false return value
Returns:
boolean False if any records matching any fields are found public

Definition at line 2274 of file model.php.

References find(), and id().

Model::joinModel ( assoc,
keys = array() 
)

Gets the name and fields to be used by a join model. This allows specifying join fields in the association definition.

Parameters:
object $model The model to be joined
mixed $with The 'with' key of the model association
array $keys Any join keys which must be merged with the keys queried
Returns:
array public

Definition at line 2713 of file model.php.

References __(), and schema().

Referenced by __saveMulti().

Model::onError (  ) 

Called when a DataSource-level error occurs.

public http://book.cakephp.org/view/687/onError

Definition at line 2805 of file model.php.

Model::query (  ) 

Returns a resultset for a given SQL statement. Custom SQL queries should be performed with this method.

Parameters:
string $sql SQL statement
Returns:
array Resultset public http://book.cakephp.org/view/456/query

Definition at line 2316 of file model.php.

References ConnectionManager::getDataSource().

Model::read ( fields = null,
id = null 
)

Returns a list of fields from the database, and sets the current model data (Model::$data) with the record found.

Parameters:
mixed $fields String of single fieldname, or an array of fieldnames.
mixed $id The ID of the record to read
Returns:
array Array of database fields, or false if not found public

Definition at line 1026 of file model.php.

References $id, find(), and id().

Model::remove ( id = null,
cascade = true 
)

Alias for del().

Parameters:
mixed $id ID of record to delete
boolean $cascade Set to true to delete records that depend on this record
Returns:
boolean True on success public
See also:
Model::del() http://book.cakephp.org/view/691/remove

Definition at line 1687 of file model.php.

References $id, and del().

Model::resetAssociations (  ) 

Called only when bindTo<ModelName>() is used. This resets the association arrays for the model back to those originally defined in the model.

Returns:
boolean Success public

Definition at line 2246 of file model.php.

References $name.

Referenced by call__(), and find().

Model::save ( data = null,
validate = true,
fieldList = array() 
)

Saves model data (based on white-list, if supplied) to the database. By default, validation occurs before save.

Parameters:
array $data Data to save.
mixed $validate Either a boolean, or an array. If a boolean, indicates whether or not to validate before saving. If an array, allows control of validate, callbacks, and fieldList
array $fieldList List of fields to allow to be written
Returns:
mixed On success Model::$data if its not empty or true, false on failure public http://book.cakephp.org/view/75/Saving-Your-Data

Definition at line 1124 of file model.php.

References $data, $validate, __saveMulti(), _clearCache(), _prepareUpdateFields(), afterSave(), beforeSave(), create(), exists(), getColumnType(), ConnectionManager::getDataSource(), hasField(), Set::merge(), set(), updateCounterCache(), String::uuid(), and validates().

Referenced by __save(), and saveField().

Model::saveAll ( data = null,
options = array() 
)

Saves multiple individual records for a single model; Also works with a single record, as well as all its associated records.

Parameters:
array $data Record data to save. This can be either a numerically-indexed array (for saving multiple records of the same type), or an array indexed by association name.
array $options Options to use when saving record data, which are as follows:
  • validate: Set to false to disable validation, true to validate each record before saving, 'first' to validate *all* records before any are saved, or 'only' to only validate the records, but not save them.
  • atomic: If true (default), will attempt to save all records in a single transaction. Should be set to false if database/table does not support transactions. If false, we return an array similar to the $data array passed, but values are set to true/false depending on whether each record saved successfully.
  • fieldList: Equivalent to the $fieldList parameter in Model::save()
Returns:
mixed True on success, or false on failure public http://book.cakephp.org/view/75/Saving-Your-Data

Definition at line 1478 of file model.php.

References $data, $validationErrors, __save(), getAssociated(), ConnectionManager::getDataSource(), id(), and Set::numeric().

Model::saveField ( name,
value,
validate = false 
)

Saves the value of a single field to the database, based on the current model ID.

Parameters:
string $name Name of the table field
mixed $value Value of the field
array $validate See $options param in Model::save(). Does not respect 'fieldList' key if passed
Returns:
boolean See Model::save() public
See also:
Model::save() http://book.cakephp.org/view/75/Saving-Your-Data

Definition at line 1100 of file model.php.

References $id, $name, $validate, create(), id(), and save().

Model::schema ( field = false  ) 

Returns an array of table metadata (column names and types) from the database. $field => keys(type, null, default, key, length, extra)

Parameters:
mixed $field Set to true to reload schema, or a string to return a specific field
Returns:
array Array of table metadata public

Definition at line 895 of file model.php.

References ConnectionManager::getDataSource().

Referenced by __generateAssociation(), create(), getColumnType(), getColumnTypes(), hasField(), joinModel(), and setSource().

Model::set ( one,
two = null 
)

This function does two things: 1) it scans the array $one for the primary key, and if that's found, it sets the current id to the value of $one[id]. For all other keys than 'id' the keys and values of $one are copied to the 'data' property of this object. 2) Returns an array with all of $one's keys and values. (Alternative indata: two strings, which are mangled to a one-item, two-dimensional array using $one for a key and $two as its value.)

Parameters:
mixed $one Array or string of data
string $two Value string for the alternative indata method
Returns:
array Data with all of $one's keys and values public

Definition at line 772 of file model.php.

References $data, deconstruct(), getAssociated(), and Set::reverse().

Referenced by create(), and save().

Model::setDataSource ( dataSource = null  ) 

Sets the DataSource to which this model is bound.

Parameters:
string $dataSource The name of the DataSource, as defined in app/config/database.php
Returns:
boolean True on success public

Definition at line 2634 of file model.php.

References Object::cakeError(), config(), and ConnectionManager::getDataSource().

Referenced by __construct(), and setSource().

Model::setInsertID ( id  ) 

Sets the ID of the last record this model inserted

Parameters:
mixed Last inserted ID public

Definition at line 2604 of file model.php.

Model::setSource ( tableName  ) 

Sets a custom table for your controller class. Used by your controller to select a database table.

Parameters:
string $tableName Name of the custom table
Returns:
void public

Definition at line 740 of file model.php.

References Object::cakeError(), ConnectionManager::getDataSource(), schema(), and setDataSource().

Referenced by __construct().

Model::unbindModel ( params,
reset = true 
)

Turn off associations on the fly.

If $reset is false, association will not be reset to the originals defined in the model

Example: Turn off the associated Model Support request, to temporarily lighten the User model: $this->User->unbindModel( array('hasMany' => array('Supportrequest')) );

Parameters:
array $params Set of bindings to unbind (indexed by binding type)
boolean $reset Set to false to make the unbinding permanent
Returns:
boolean Success public http://book.cakephp.org/view/86/Creating-and-Destroying-Associations-on-the-Fly

Definition at line 553 of file model.php.

Model::updateAll ( fields,
conditions = true 
)

Updates multiple model records based on a set of conditions.

Parameters:
array $fields Set of fields and values, indexed by fields. Fields are treated as SQL snippets, to insert literal values manually escape your data.
mixed $conditions Conditions to match, true for all records
Returns:
boolean True on success, false on failure public http://book.cakephp.org/view/75/Saving-Your-Data

Definition at line 1673 of file model.php.

References ConnectionManager::getDataSource().

Model::updateCounterCache ( keys = array(),
created = false 
)

Updates the counter cache of belongsTo associations after a save or delete operation

Parameters:
array $keys Optional foreign key data, defaults to the information $this->data
boolean $created True if a new record was created, otherwise only associations with 'counterScope' defined get updated
Returns:
void public

Definition at line 1384 of file model.php.

References $recursive, escapeField(), field(), find(), hasField(), and underscore().

Referenced by del(), and save().

Model::validates ( options = array()  ) 

Returns true if all fields pass validation.

Parameters:
string $options An optional array of custom options to be made available in the beforeValidate callback
Returns:
boolean True if there are no errors public http://book.cakephp.org/view/410/Validating-Data-from-the-Controller

Definition at line 2329 of file model.php.

References invalidFields().

Referenced by __save(), and save().


Member Data Documentation

Model::$__affectedRows = null

Definition at line 322 of file model.php.

Model::$__associationKeys

Initial value:

 array(
        'belongsTo' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'counterCache'),
        'hasOne' => array('className', 'foreignKey','conditions', 'fields','order', 'dependent'),
        'hasMany' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'),
        'hasAndBelongsToMany' => array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery')
    )

Definition at line 282 of file model.php.

Model::$__associations = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany')

Definition at line 294 of file model.php.

Model::$__backAssociation = array()

Definition at line 301 of file model.php.

Model::$__exists = null

Definition at line 275 of file model.php.

Model::$__insertID = null

Definition at line 308 of file model.php.

Model::$__numRows = null

Definition at line 315 of file model.php.

Model::$_findMethods

Initial value:

 array(
        'all' => true, 'first' => true, 'count' => true,
        'neighbors' => true, 'list' => true, 'threaded' => true
    )

Definition at line 329 of file model.php.

Model::$_schema = null

Definition at line 106 of file model.php.

Model::$actsAs = null

Reimplemented in AclNode, and Permission.

Definition at line 220 of file model.php.

Model::$alias = null

Definition at line 147 of file model.php.

Referenced by __construct(), escapeField(), and AclNode::node().

Model::$Behaviors = null

Definition at line 227 of file model.php.

Model::$belongsTo = array()

Reimplemented in AcoAction, and Permission.

Definition at line 185 of file model.php.

Model::$cacheQueries = false

Reimplemented in AclNode, and Permission.

Definition at line 177 of file model.php.

Model::$cacheSources = true

Definition at line 241 of file model.php.

Model::$data = array()

Definition at line 83 of file model.php.

Referenced by __generateAssociation(), __saveMulti(), _prepareUpdateFields(), create(), deconstruct(), field(), save(), saveAll(), and set().

Model::$displayField = null

Definition at line 67 of file model.php.

Model::$findQueryType = null

Definition at line 248 of file model.php.

Model::$hasAndBelongsToMany = array()

Reimplemented in Aco, and Aro.

Definition at line 209 of file model.php.

Model::$hasMany = array()

Definition at line 201 of file model.php.

Model::$hasOne = array()

Definition at line 193 of file model.php.

Model::$id = false

Definition at line 75 of file model.php.

Referenced by __construct(), __saveMulti(), del(), read(), remove(), and saveField().

Model::$logTransactions = false

Definition at line 161 of file model.php.

Model::$name = null

Reimplemented in Aco, AcoAction, Aro, and Permission.

Definition at line 140 of file model.php.

Referenced by __construct(), bind(), field(), hasField(), AclNode::node(), resetAssociations(), and saveField().

Model::$order = null

Definition at line 268 of file model.php.

Referenced by field().

Model::$primaryKey = null

Definition at line 98 of file model.php.

Model::$recursive = 1

Definition at line 257 of file model.php.

Referenced by field(), and updateCounterCache().

Model::$table = false

Definition at line 90 of file model.php.

Referenced by __construct(), and AclNode::node().

Model::$tablePrefix = null

Definition at line 132 of file model.php.

Model::$tableToModel = array()

Definition at line 154 of file model.php.

Model::$transactional = false

Definition at line 168 of file model.php.

Model::$useDbConfig = 'default'

Definition at line 51 of file model.php.

Model::$useTable = null

Reimplemented in Permission.

Definition at line 59 of file model.php.

Model::$validate = array()

Definition at line 116 of file model.php.

Referenced by invalidFields(), save(), and saveField().

Model::$validationErrors = array()

Definition at line 124 of file model.php.

Referenced by saveAll().

Model::$whitelist = array()

Definition at line 234 of file model.php.

Referenced by invalidFields().


The documentation for this class was generated from the following file:
Generated on Sun Nov 22 00:30:56 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7