mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Updating docblock wording and @link ties.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7810 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
44781d2ef9
commit
89bf77ae01
1 changed files with 147 additions and 97 deletions
|
@ -34,11 +34,11 @@ App::import('Core', array('ClassRegistry', 'Overloadable', 'Validation', 'Behavi
|
|||
* DBO-backed object data model.
|
||||
* Automatically selects a database table name based on a pluralized lowercase object class name
|
||||
* (i.e. class 'User' => table 'users'; class 'Man' => table 'men')
|
||||
* The table is required to have at least 'id auto_increment', 'created datetime',
|
||||
* and 'modified datetime' fields.
|
||||
* The table is required to have at least 'id auto_increment' primary key.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.model
|
||||
* @link http://book.cakephp.org/view/66/Models
|
||||
*/
|
||||
class Model extends Overloadable {
|
||||
/**
|
||||
|
@ -46,13 +46,15 @@ class Model extends Overloadable {
|
|||
*
|
||||
* @var string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/435/useDbConfig
|
||||
*/
|
||||
var $useDbConfig = 'default';
|
||||
/**
|
||||
* Custom database table name.
|
||||
* Custom database table name, or null/false if no table association is desired.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/436/useTable
|
||||
*/
|
||||
var $useTable = null;
|
||||
/**
|
||||
|
@ -60,20 +62,23 @@ class Model extends Overloadable {
|
|||
*
|
||||
* @var string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/438/displayField
|
||||
*/
|
||||
var $displayField = null;
|
||||
/**
|
||||
* Value of the primary key ID of the record that this model is currently pointing to
|
||||
* Value of the primary key ID of the record that this model is currently pointing to.
|
||||
* Automatically set after database insertions.
|
||||
*
|
||||
* @var mixed
|
||||
* @access public
|
||||
*/
|
||||
var $id = false;
|
||||
/**
|
||||
* Container for the data that this model gets from persistent storage (the database).
|
||||
* Container for the data that this model gets from persistent storage (usually, a database).
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/441/data
|
||||
*/
|
||||
var $data = array();
|
||||
/**
|
||||
|
@ -84,17 +89,19 @@ class Model extends Overloadable {
|
|||
*/
|
||||
var $table = false;
|
||||
/**
|
||||
* The name of the ID field for this Model.
|
||||
* The name of the primary key field for this model.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/437/primaryKey
|
||||
*/
|
||||
var $primaryKey = null;
|
||||
/**
|
||||
* Table metadata
|
||||
* Field-by-field table metadata.
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
* @link http://book.cakephp.org/view/442/_schema
|
||||
*/
|
||||
var $_schema = null;
|
||||
/**
|
||||
|
@ -103,13 +110,16 @@ class Model extends Overloadable {
|
|||
*
|
||||
* @var array
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/443/validate
|
||||
* @link http://book.cakephp.org/view/125/Data-Validation
|
||||
*/
|
||||
var $validate = array();
|
||||
/**
|
||||
* Errors in validation
|
||||
* List of validation errors.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/410/Validating-Data-from-the-Controller
|
||||
*/
|
||||
var $validationErrors = array();
|
||||
/**
|
||||
|
@ -117,6 +127,7 @@ class Model extends Overloadable {
|
|||
*
|
||||
* @var string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/475/tablePrefix
|
||||
*/
|
||||
var $tablePrefix = null;
|
||||
/**
|
||||
|
@ -124,6 +135,7 @@ class Model extends Overloadable {
|
|||
*
|
||||
* @var string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/444/name
|
||||
*/
|
||||
var $name = null;
|
||||
/**
|
||||
|
@ -134,21 +146,21 @@ class Model extends Overloadable {
|
|||
*/
|
||||
var $alias = null;
|
||||
/**
|
||||
* List of table names included in the Model description. Used for associations.
|
||||
* List of table names included in the model description. Used for associations.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tableToModel = array();
|
||||
/**
|
||||
* Whether or not transactions for this model should be logged
|
||||
* Whether or not to log transactions for this model.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $logTransactions = false;
|
||||
/**
|
||||
* Whether or not to enable transactions for this model (i.e. BEGIN/COMMIT/ROLLBACK)
|
||||
* Whether or not to enable transactions for this model (i.e. BEGIN/COMMIT/ROLLBACK statements)
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
|
@ -156,101 +168,113 @@ class Model extends Overloadable {
|
|||
var $transactional = false;
|
||||
/**
|
||||
* Whether or not to cache queries for this model. This enables in-memory
|
||||
* caching only, the results are not stored beyond this execution.
|
||||
* caching only, the results are not stored beyond the current request.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/445/cacheQueries
|
||||
*/
|
||||
var $cacheQueries = false;
|
||||
/**
|
||||
* belongsTo association
|
||||
* Detailed list of belongsTo associations.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/81/belongsTo
|
||||
*/
|
||||
var $belongsTo = array();
|
||||
/**
|
||||
* hasOne association
|
||||
* Detailed list of hasOne associations.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/80/hasOne
|
||||
*/
|
||||
var $hasOne = array();
|
||||
/**
|
||||
* hasMany association
|
||||
* Detailed list of hasMany associations.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/82/hasMany
|
||||
*/
|
||||
var $hasMany = array();
|
||||
/**
|
||||
* hasAndBelongsToMany association
|
||||
* Detailed list of hasAndBelongsToMany associations.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM
|
||||
*/
|
||||
var $hasAndBelongsToMany = array();
|
||||
/**
|
||||
* List of behaviors to load when the model object is initialized. Settings can be
|
||||
* passed to behaviors by using the behavior name as index. Eg:
|
||||
*
|
||||
* array('Translate', 'MyBehavior' => array('setting1' => 'value1'))
|
||||
* var $actsAs = array('Translate', 'MyBehavior' => array('setting1' => 'value1'))
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/90/Using-Behaviors
|
||||
*/
|
||||
var $actsAs = null;
|
||||
/**
|
||||
* Holds the Behavior objects currently bound to this model
|
||||
* Holds the Behavior objects currently bound to this model.
|
||||
*
|
||||
* @var object
|
||||
* @access public
|
||||
*/
|
||||
var $Behaviors = null;
|
||||
/**
|
||||
* Whitelist of fields allowed to be saved
|
||||
* Whitelist of fields allowed to be saved.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $whitelist = array();
|
||||
/**
|
||||
* Should sources for this model be cached.
|
||||
* Whether or not to cache sources for this model.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $cacheSources = true;
|
||||
/**
|
||||
* Type of find query currently executing
|
||||
* Type of find query currently executing.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $findQueryType = null;
|
||||
/**
|
||||
* Depth of recursive association
|
||||
* Number of associations to recurse through during find calls. Fetches only
|
||||
* the first level by default.
|
||||
*
|
||||
* @var integer
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/439/recursive
|
||||
*/
|
||||
var $recursive = 1;
|
||||
/**
|
||||
* Default ordering of model records
|
||||
* The column name(s) and direction(s) to order find results by default.
|
||||
*
|
||||
* var $order = "Post.created DESC";
|
||||
* var $order = array("Post.view_count DESC", "Post.rating DESC");
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/440/order
|
||||
*/
|
||||
var $order = null;
|
||||
/**
|
||||
* Whether or not the model record exists, set by Model::exists()
|
||||
* Whether or not the model record exists, set by Model::exists().
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $__exists = null;
|
||||
/**
|
||||
* Default association keys
|
||||
* Default list of association keys.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
|
@ -261,42 +285,42 @@ class Model extends Overloadable {
|
|||
'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'));
|
||||
/**
|
||||
* Holds provided/generated association key names and other data for all associations
|
||||
* Holds provided/generated association key names and other data for all associations.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__associations = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
/**
|
||||
* Holds model associations temporarily to allow for dynamic (un)binding
|
||||
* Holds model associations temporarily to allow for dynamic (un)binding.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__backAssociation = array();
|
||||
/**
|
||||
* The last inserted ID of the data that this model created
|
||||
* The ID of the model record that was last inserted.
|
||||
*
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $__insertID = null;
|
||||
/**
|
||||
* The number of records returned by the last query
|
||||
* The number of records returned by the last query.
|
||||
*
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $__numRows = null;
|
||||
/**
|
||||
* The number of records affected by the last query
|
||||
* The number of records affected by the last query.
|
||||
*
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $__affectedRows = null;
|
||||
/**
|
||||
* List of valid finder method options
|
||||
* List of valid finder method options, supplied as the first parameter to find().
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
|
@ -306,7 +330,7 @@ class Model extends Overloadable {
|
|||
'neighbors' => true, 'list' => true, 'threaded' => true
|
||||
);
|
||||
/**
|
||||
* Constructor. Binds the Model's database table to the object.
|
||||
* Constructor. Binds the model's database table to the object.
|
||||
*
|
||||
* @param integer $id Set this ID for this model on startup
|
||||
* @param string $table Name of database table to use.
|
||||
|
@ -472,6 +496,7 @@ class Model extends Overloadable {
|
|||
* @param boolean $reset Set to false to make the binding permanent
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/86/Creating-and-Destroying-Associations-on-the-Fly
|
||||
*/
|
||||
function bindModel($params, $reset = true) {
|
||||
foreach ($params as $assoc => $model) {
|
||||
|
@ -509,6 +534,7 @@ class Model extends Overloadable {
|
|||
* @param boolean $reset Set to false to make the unbinding permanent
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/86/Creating-and-Destroying-Associations-on-the-Fly
|
||||
*/
|
||||
function unbindModel($params, $reset = true) {
|
||||
foreach ($params as $assoc => $models) {
|
||||
|
@ -525,7 +551,7 @@ class Model extends Overloadable {
|
|||
return true;
|
||||
}
|
||||
/**
|
||||
* Create a set of associations
|
||||
* Create a set of associations.
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
|
@ -577,7 +603,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Private helper method to create associated models of given class.
|
||||
* Private helper method to create associated models of a given class.
|
||||
*
|
||||
* @param string $assoc Association name
|
||||
* @param string $className Class name
|
||||
|
@ -608,7 +634,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Build array-based association from string.
|
||||
* Build an array-based association from string.
|
||||
*
|
||||
* @param string $type 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'
|
||||
* @return void
|
||||
|
@ -771,7 +797,7 @@ class Model extends Overloadable {
|
|||
return $data;
|
||||
}
|
||||
/**
|
||||
* Deconstructs a complex data type (array or object) into a single field value
|
||||
* Deconstructs a complex data type (array or object) into a single field value.
|
||||
*
|
||||
* @param string $field The name of the field to be deconstructed
|
||||
* @param mixed $data An array or object to be deconstructed into a field
|
||||
|
@ -866,7 +892,7 @@ class Model extends Overloadable {
|
|||
return $cols;
|
||||
}
|
||||
/**
|
||||
* Returns the column type of a column in the model
|
||||
* Returns the column type of a column in the model.
|
||||
*
|
||||
* @param string $column The name of the model column
|
||||
* @return string Column type
|
||||
|
@ -891,7 +917,7 @@ class Model extends Overloadable {
|
|||
return null;
|
||||
}
|
||||
/**
|
||||
* Returns true if this Model has given field in its database table.
|
||||
* Returns true if the supplied field exists in the model's database table.
|
||||
*
|
||||
* @param mixed $name Name of field to look for, or an array of names
|
||||
* @return mixed If $name is a string, returns a boolean indicating whether the field exists.
|
||||
|
@ -920,13 +946,15 @@ class Model extends Overloadable {
|
|||
}
|
||||
/**
|
||||
* Initializes the model for writing a new record, loading the default values
|
||||
* for those fields that are not defined in $data.
|
||||
* for those fields that are not defined in $data. Especially helpful for
|
||||
* saving data in loops.
|
||||
*
|
||||
* @param mixed $data Optional data array to assign to the model after it is created. If null or false,
|
||||
* schema data defaults are not merged.
|
||||
* @param boolean $filterKey If true, overwrites any primary key input with an empty value
|
||||
* @return array The current Model::data; after merging $data and/or defaults from database
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/75/Saving-Your-Data
|
||||
*/
|
||||
function create($data = array(), $filterKey = false) {
|
||||
$defaults = array();
|
||||
|
@ -978,13 +1006,15 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Returns contents of a field in a query matching given conditions.
|
||||
* Returns the contents of a single field given the supplied conditions, in the
|
||||
* supplied order.
|
||||
*
|
||||
* @param string $name Name of field to get
|
||||
* @param array $conditions SQL conditions (defaults to NULL)
|
||||
* @param string $order SQL ORDER BY fragment
|
||||
* @return string field contents, or false if not found
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/453/field
|
||||
*/
|
||||
function field($name, $conditions = null, $order = null) {
|
||||
if ($conditions === null && $this->id !== false) {
|
||||
|
@ -1015,7 +1045,8 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Saves a single field to the database.
|
||||
* Saves the value of a single field to the database, based on the current
|
||||
* model ID.
|
||||
*
|
||||
* @param string $name Name of the table field
|
||||
* @param mixed $value Value of the field
|
||||
|
@ -1023,6 +1054,7 @@ class Model extends Overloadable {
|
|||
* @return boolean See Model::save()
|
||||
* @access public
|
||||
* @see Model::save()
|
||||
* @link http://book.cakephp.org/view/75/Saving-Your-Data
|
||||
*/
|
||||
function saveField($name, $value, $validate = false) {
|
||||
$id = $this->id;
|
||||
|
@ -1036,7 +1068,8 @@ class Model extends Overloadable {
|
|||
return $this->save(array($this->alias => array($this->primaryKey => $id, $name => $value)), $options);
|
||||
}
|
||||
/**
|
||||
* Saves model data to the database. By default, validation occurs before save.
|
||||
* Saves model data (based on white-list, if supplied) to the database. By
|
||||
* default, validation occurs before save.
|
||||
*
|
||||
* @param array $data Data to save.
|
||||
* @param mixed $validate Either a boolean, or an array.
|
||||
|
@ -1045,6 +1078,7 @@ class Model extends Overloadable {
|
|||
* @param array $fieldList List of fields to allow to be written
|
||||
* @return mixed On success Model::$data if its not empty or true, false on failure
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/75/Saving-Your-Data
|
||||
*/
|
||||
function save($data = null, $validate = true, $fieldList = array()) {
|
||||
$defaults = array('validate' => true, 'fieldList' => array(), 'callbacks' => true);
|
||||
|
@ -1317,8 +1351,8 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Saves (a) multiple individual records for a single model or (b) this record, as well as
|
||||
* all associated records
|
||||
* Saves multiple individual records for a single model; Also works with a single record, as well as
|
||||
* all its associated records.
|
||||
*
|
||||
* @param 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.
|
||||
|
@ -1333,6 +1367,8 @@ class Model extends Overloadable {
|
|||
* - fieldList: Equivalent to the $fieldList parameter in Model::save()
|
||||
* @return mixed True on success, or false on failure
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/84/Saving-Related-Model-Data-hasOne-hasMany-belongsTo
|
||||
* @link http://book.cakephp.org/view/75/Saving-Your-Data
|
||||
*/
|
||||
function saveAll($data = null, $options = array()) {
|
||||
if (empty($data)) {
|
||||
|
@ -1504,7 +1540,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Private helper method used by saveAll
|
||||
* Private helper method used by saveAll.
|
||||
*
|
||||
* @return boolean Success
|
||||
* @access private
|
||||
|
@ -1521,37 +1557,40 @@ class Model extends Overloadable {
|
|||
return true;
|
||||
}
|
||||
/**
|
||||
* Allows model records to be updated based on a set of conditions
|
||||
* Updates multiple model records based on a set of conditions.
|
||||
*
|
||||
* @param array $fields Set of fields and values, indexed by fields.
|
||||
* Fields are treated as SQL snippets, to insert literal values manually escape your data.
|
||||
* @param mixed $conditions Conditions to match, true for all records
|
||||
* @return boolean True on success, false on failure
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/75/Saving-Your-Data
|
||||
*/
|
||||
function updateAll($fields, $conditions = true) {
|
||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||
return $db->update($this, $fields, null, $conditions);
|
||||
}
|
||||
/**
|
||||
* Synonym for del().
|
||||
* Alias for del().
|
||||
*
|
||||
* @param mixed $id ID of record to delete
|
||||
* @param boolean $cascade Set to true to delete records that depend on this record
|
||||
* @return boolean True on success
|
||||
* @access public
|
||||
* @see Model::del()
|
||||
* @link http://book.cakephp.org/view/691/remove
|
||||
*/
|
||||
function remove($id = null, $cascade = true) {
|
||||
return $this->del($id, $cascade);
|
||||
}
|
||||
/**
|
||||
* Removes record for given id. If no id is given, the current id is used. Returns true on success.
|
||||
* Removes record for given ID. If no ID is given, the current ID is used. Returns true on success.
|
||||
*
|
||||
* @param mixed $id ID of record to delete
|
||||
* @param boolean $cascade Set to true to delete records that depend on this record
|
||||
* @return boolean True on success
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/690/del
|
||||
*/
|
||||
function del($id = null, $cascade = true) {
|
||||
if (!empty($id)) {
|
||||
|
@ -1587,7 +1626,7 @@ class Model extends Overloadable {
|
|||
return false;
|
||||
}
|
||||
/**
|
||||
* Synonym for del().
|
||||
* Alias for del().
|
||||
*
|
||||
* @param mixed $id ID of record to delete
|
||||
* @param boolean $cascade Set to true to delete records that depend on this record
|
||||
|
@ -1599,7 +1638,7 @@ class Model extends Overloadable {
|
|||
return $this->del($id, $cascade);
|
||||
}
|
||||
/**
|
||||
* Cascades model deletes to hasMany and hasOne relationships.
|
||||
* Cascades model deletes through associated hasMany and hasOne child records.
|
||||
*
|
||||
* @param string $id ID of record that was deleted
|
||||
* @param boolean $cascade Set to true to delete records that depend on this record
|
||||
|
@ -1639,7 +1678,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Cascades model deletes to HABTM join keys.
|
||||
* Cascades model deletes through HABTM join keys.
|
||||
*
|
||||
* @param string $id ID of record that was deleted
|
||||
* @return void
|
||||
|
@ -1662,13 +1701,14 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Allows model records to be deleted based on a set of conditions
|
||||
* Deletes multiple model records based on a set of conditions.
|
||||
*
|
||||
* @param mixed $conditions Conditions to match
|
||||
* @param boolean $cascade Set to true to delete records that depend on this record
|
||||
* @param boolean $callbacks Run callbacks (not being used)
|
||||
* @return boolean True on success, false on failure
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/692/deleteAll
|
||||
*/
|
||||
function deleteAll($conditions, $cascade = true, $callbacks = false) {
|
||||
if (empty($conditions)) {
|
||||
|
@ -1708,7 +1748,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Collects foreign keys from associations
|
||||
* Collects foreign keys from associations.
|
||||
*
|
||||
* @return array
|
||||
* @access private
|
||||
|
@ -1724,7 +1764,7 @@ class Model extends Overloadable {
|
|||
return $result;
|
||||
}
|
||||
/**
|
||||
* Returns true if a record with set id exists.
|
||||
* Returns true if a record with the currently set ID exists.
|
||||
*
|
||||
* @param boolean $reset if true will force database query
|
||||
* @return boolean True if such a record exists
|
||||
|
@ -1750,7 +1790,7 @@ class Model extends Overloadable {
|
|||
return $this->__exists = ($this->find('count', $query) > 0);
|
||||
}
|
||||
/**
|
||||
* Returns true if a record that meets given conditions exists
|
||||
* Returns true if a record that meets given conditions exists.
|
||||
*
|
||||
* @param array $conditions SQL conditions array
|
||||
* @return boolean True if such a record exists
|
||||
|
@ -1760,12 +1800,7 @@ class Model extends Overloadable {
|
|||
return ($this->find('count', array('conditions' => $conditions, 'recursive' => -1)) != false);
|
||||
}
|
||||
/**
|
||||
* Return a result set array.
|
||||
*
|
||||
* By using the $recursive parameter, the call can access further "levels of association" than
|
||||
* the ones this model is directly associated to.
|
||||
*
|
||||
* Eg: find(array('name' => 'Thomas Anderson'), array('name', 'email'), 'field3 DESC', 2);
|
||||
* 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 ),
|
||||
|
@ -1791,6 +1826,7 @@ class Model extends Overloadable {
|
|||
* @param integer $recursive The number of levels deep to fetch associated records
|
||||
* @return array Array of records
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/449/find
|
||||
*/
|
||||
function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
|
||||
if (!is_string($conditions) || (is_string($conditions) && !array_key_exists($conditions, $this->_findMethods))) {
|
||||
|
@ -1871,6 +1907,7 @@ class Model extends Overloadable {
|
|||
* @param array $data
|
||||
* @return array
|
||||
* @access protected
|
||||
* @see Model::find()
|
||||
*/
|
||||
function _findFirst($state, $query, $results = array()) {
|
||||
if ($state == 'before') {
|
||||
|
@ -1894,6 +1931,7 @@ class Model extends Overloadable {
|
|||
* @param array $data
|
||||
* @return int The number of records found, or false
|
||||
* @access protected
|
||||
* @see Model::find()
|
||||
*/
|
||||
function _findCount($state, $query, $results = array()) {
|
||||
if ($state == 'before') {
|
||||
|
@ -1924,6 +1962,7 @@ class Model extends Overloadable {
|
|||
* @param array $data
|
||||
* @return array Key/value pairs of primary keys/display field values of all records found
|
||||
* @access protected
|
||||
* @see Model::find()
|
||||
*/
|
||||
function _findList($state, $query, $results = array()) {
|
||||
if ($state == 'before') {
|
||||
|
@ -1974,10 +2013,8 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* findNeighbors method
|
||||
*
|
||||
* The before logic will find the previous field value, the after logic will then find the 'wrapping'
|
||||
* rows and return them
|
||||
* Detects the previous field's value, then uses logic to find the 'wrapping'
|
||||
* rows and return them.
|
||||
*
|
||||
* @param string $state Either "before" or "after"
|
||||
* @param mixed $query
|
||||
|
@ -2034,8 +2071,6 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* findThreaded method
|
||||
*
|
||||
* 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
|
||||
*
|
||||
|
@ -2082,7 +2117,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Passes query results through model and behavior afterFilter() methods
|
||||
* Passes query results through model and behavior afterFilter() methods.
|
||||
*
|
||||
* @param array Results to filter
|
||||
* @param boolean $primary If this is the primary model results (results from model where the find operation was performed)
|
||||
|
@ -2097,9 +2132,9 @@ class Model extends Overloadable {
|
|||
return $this->afterFind($results, $primary);
|
||||
}
|
||||
/**
|
||||
* Method is called only when bindTo<ModelName>() is used.
|
||||
* Called only when bindTo<ModelName>() is used.
|
||||
* This resets the association arrays for the model back
|
||||
* to the original as set in the model.
|
||||
* to those originally defined in the model.
|
||||
*
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
|
@ -2125,7 +2160,7 @@ class Model extends Overloadable {
|
|||
return true;
|
||||
}
|
||||
/**
|
||||
* False if any fields passed match any (by default, all if $or = false) of their matching values.
|
||||
* Returns false if any fields passed match any (by default, all if $or = false) of their matching values.
|
||||
*
|
||||
* @param array $fields Field/value pairs to search (if no values specified, they are pulled from $this->data)
|
||||
* @param boolean $or If false, all fields specified must match in order for a false return value
|
||||
|
@ -2167,11 +2202,12 @@ class Model extends Overloadable {
|
|||
return ($this->find('count', array('conditions' => $fields, 'recursive' => -1)) == 0);
|
||||
}
|
||||
/**
|
||||
* Returns a resultset for given SQL statement. Generic SQL queries should be made with this method.
|
||||
* Returns a resultset for a given SQL statement. Custom SQL queries should be performed with this method.
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @return array Resultset
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/456/query
|
||||
*/
|
||||
function query() {
|
||||
$params = func_get_args();
|
||||
|
@ -2179,11 +2215,12 @@ class Model extends Overloadable {
|
|||
return call_user_func_array(array(&$db, 'query'), $params);
|
||||
}
|
||||
/**
|
||||
* Returns true if all fields pass validation, otherwise false.
|
||||
* Returns true if all fields pass validation.
|
||||
*
|
||||
* @param string $options An optional array of custom options to be made available in the beforeValidate callback
|
||||
* @return boolean True if there are no errors
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/410/Validating-Data-from-the-Controller
|
||||
*/
|
||||
function validates($options = array()) {
|
||||
$errors = $this->invalidFields($options);
|
||||
|
@ -2193,11 +2230,12 @@ class Model extends Overloadable {
|
|||
return $errors;
|
||||
}
|
||||
/**
|
||||
* Returns an array of fields that do not meet validation.
|
||||
* Returns an array of fields that have failed validation.
|
||||
*
|
||||
* @param string $options An optional array of custom options to be made available in the beforeValidate callback
|
||||
* @return array Array of invalid fields
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/410/Validating-Data-from-the-Controller
|
||||
*/
|
||||
function invalidFields($options = array()) {
|
||||
if (
|
||||
|
@ -2336,8 +2374,8 @@ class Model extends Overloadable {
|
|||
return $this->validationErrors;
|
||||
}
|
||||
/**
|
||||
* Sets a field as invalid, optionally setting the name of validation
|
||||
* rule (in case of multiple validation for field) that was broken
|
||||
* Marks a field as invalid, optionally setting the name of validation
|
||||
* rule (in case of multiple validation for field) that was broken.
|
||||
*
|
||||
* @param string $field The name of the field to invalidate
|
||||
* @param mixed $value Name of validation rule that was not failed. If no validation key
|
||||
|
@ -2351,7 +2389,7 @@ class Model extends Overloadable {
|
|||
$this->validationErrors[$field] = $value;
|
||||
}
|
||||
/**
|
||||
* Returns true if given field name is a foreign key in this Model.
|
||||
* Returns true if given field name is a foreign key in this model.
|
||||
*
|
||||
* @param string $field Returns true if the input string ends in "_id"
|
||||
* @return boolean True if the field is a foreign key listed in the belongsTo array.
|
||||
|
@ -2367,7 +2405,7 @@ class Model extends Overloadable {
|
|||
return in_array($field, $foreignKeys);
|
||||
}
|
||||
/**
|
||||
* Gets the display field for this model
|
||||
* Returns the display field for this model.
|
||||
*
|
||||
* @return string The name of the display field for this Model (i.e. 'name', 'title').
|
||||
* @access public
|
||||
|
@ -2376,7 +2414,7 @@ class Model extends Overloadable {
|
|||
return $this->displayField;
|
||||
}
|
||||
/**
|
||||
* Escapes the field name and prepends the model name. Escaping will be done according to the current database driver's rules.
|
||||
* Escapes the field name and prepends the model name. Escaping is done according to the current database driver's rules.
|
||||
*
|
||||
* @param string $field Field to escape (e.g: id)
|
||||
* @param string $alias Alias for the model (e.g: Post)
|
||||
|
@ -2481,7 +2519,7 @@ class Model extends Overloadable {
|
|||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the ID of the last record this Model inserted
|
||||
* Returns the ID of the last record this model inserted.
|
||||
*
|
||||
* @return mixed Last inserted ID
|
||||
* @access public
|
||||
|
@ -2490,7 +2528,7 @@ class Model extends Overloadable {
|
|||
return $this->getInsertID();
|
||||
}
|
||||
/**
|
||||
* Returns the ID of the last record this Model inserted
|
||||
* Returns the ID of the last record this model inserted.
|
||||
*
|
||||
* @return mixed Last inserted ID
|
||||
* @access public
|
||||
|
@ -2499,7 +2537,7 @@ class Model extends Overloadable {
|
|||
return $this->__insertID;
|
||||
}
|
||||
/**
|
||||
* Sets the ID of the last record this Model inserted
|
||||
* Sets the ID of the last record this model inserted
|
||||
*
|
||||
* @param mixed Last inserted ID
|
||||
* @access public
|
||||
|
@ -2508,7 +2546,7 @@ class Model extends Overloadable {
|
|||
$this->__insertID = $id;
|
||||
}
|
||||
/**
|
||||
* Returns the number of rows returned from the last query
|
||||
* Returns the number of rows returned from the last query.
|
||||
*
|
||||
* @return int Number of rows
|
||||
* @access public
|
||||
|
@ -2518,7 +2556,7 @@ class Model extends Overloadable {
|
|||
return $db->lastNumRows();
|
||||
}
|
||||
/**
|
||||
* Returns the number of rows affected by the last query
|
||||
* Returns the number of rows affected by the last query.
|
||||
*
|
||||
* @return int Number of rows
|
||||
* @access public
|
||||
|
@ -2528,7 +2566,7 @@ class Model extends Overloadable {
|
|||
return $db->lastAffected();
|
||||
}
|
||||
/**
|
||||
* Sets the DataSource to which this model is bound
|
||||
* Sets the DataSource to which this model is bound.
|
||||
*
|
||||
* @param string $dataSource The name of the DataSource, as defined in app/config/database.php
|
||||
* @return boolean True on success
|
||||
|
@ -2567,7 +2605,7 @@ class Model extends Overloadable {
|
|||
return $db;
|
||||
}
|
||||
/**
|
||||
* Gets all the models with which this model is associated
|
||||
* Gets all the models with which this model is associated.
|
||||
*
|
||||
* @param string $type Only result associations of this type
|
||||
* @return array Associations
|
||||
|
@ -2624,79 +2662,91 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Before find callback
|
||||
* Called before each find operation. Return false if you want to halt the find
|
||||
* call, otherwise return the (modified) query data.
|
||||
*
|
||||
* @param array $queryData Data used to execute this query, i.e. conditions, order, etc.
|
||||
* @return mixed true if the operation should continue, false if it should abort; or, modified $queryData to continue with new $queryData
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/680/beforeFind
|
||||
*/
|
||||
function beforeFind($queryData) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* After find callback. Can be used to modify any results returned by find().
|
||||
* Called after each find operation. Can be used to modify any results returned by find().
|
||||
* Return value should be the (modified) results.
|
||||
*
|
||||
* @param mixed $results The results of the find operation
|
||||
* @param boolean $primary Whether this model is being queried directly (vs. being queried as an association)
|
||||
* @return mixed Result of the find operation
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/681/afterFind
|
||||
*/
|
||||
function afterFind($results, $primary = false) {
|
||||
return $results;
|
||||
}
|
||||
/**
|
||||
* Before save callback
|
||||
* Called before each save operation, after validation. Return a non-true result
|
||||
* to halt the save.
|
||||
*
|
||||
* @return boolean True if the operation should continue, false if it should abort
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/683/beforeSave
|
||||
*/
|
||||
function beforeSave($options = array()) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* After save callback
|
||||
* Called after each successful save operation.
|
||||
*
|
||||
* @param boolean $created True if this save created a new record
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/684/afterSave
|
||||
*/
|
||||
function afterSave($created) {
|
||||
}
|
||||
/**
|
||||
* Before delete callback
|
||||
* Called after every deletion operation.
|
||||
*
|
||||
* @param boolean $cascade If true records that depend on this record will also be deleted
|
||||
* @return boolean True if the operation should continue, false if it should abort
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/685/beforeDelete
|
||||
*/
|
||||
function beforeDelete($cascade = true) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* After delete callback
|
||||
* Called after every deletion operation.
|
||||
*
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/686/afterDelete
|
||||
*/
|
||||
function afterDelete() {
|
||||
}
|
||||
/**
|
||||
* Before validate callback
|
||||
* Called during save operations, before validation. Please note that custom
|
||||
* validation rules can be defined in $validate.
|
||||
*
|
||||
* @return boolean True if validate operation should continue, false to abort
|
||||
* @param $options array Options passed from model::save(), see $options of model::save().
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/682/beforeValidate
|
||||
*/
|
||||
function beforeValidate($options = array()) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* DataSource error callback
|
||||
* Called when a DataSource-level error occurs.
|
||||
*
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/687/onError
|
||||
*/
|
||||
function onError() {
|
||||
}
|
||||
/**
|
||||
* Private method. Clears cache for this model
|
||||
* Private method. Clears cache for this model.
|
||||
*
|
||||
* @param string $type If null this deletes cached views if Cache.check is true
|
||||
* Will be used to allow deleting query cache also
|
||||
|
@ -2726,7 +2776,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Called when serializing a model
|
||||
* Called when serializing a model.
|
||||
*
|
||||
* @return array Set of object variable names this model has
|
||||
* @access private
|
||||
|
@ -2736,7 +2786,7 @@ class Model extends Overloadable {
|
|||
return $return;
|
||||
}
|
||||
/**
|
||||
* Called when unserializing a model
|
||||
* Called when de-serializing a model.
|
||||
*
|
||||
* @access private
|
||||
* @todo
|
||||
|
|
Loading…
Add table
Reference in a new issue