@@ -1575,7 +1575,8 @@ public function field($name, $conditions = null, $order = null) {
1575
1575
* @param mixed $value Value of the field
1576
1576
* @param boolean|array $validate Either a boolean, or an array.
1577
1577
* If a boolean, indicates whether or not to validate before saving.
1578
- * If an array, allows control of 'validate' and 'callbacks' options.
1578
+ * If an array, allows control of 'validate', 'callbacks' and 'counterCache' options.
1579
+ * See Model::save() for details of each options.
1579
1580
* @return boolean See Model::save()
1580
1581
* @see Model::save()
1581
1582
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-savefield-string-fieldname-string-fieldvalue-validate-false
@@ -1598,13 +1599,20 @@ public function saveField($name, $value, $validate = false) {
1598
1599
* @param array $data Data to save.
1599
1600
* @param boolean|array $validate Either a boolean, or an array.
1600
1601
* If a boolean, indicates whether or not to validate before saving.
1601
- * If an array, allows control of validate, callbacks, and fieldList
1602
+ * If an array, it can have one of the following options:
1603
+ * - validate: Boolean as mentioned above
1604
+ * - fieldList: See $fieldList parameter
1605
+ * - callbacks: Controls callbacks triggering. Valid values: true, false, 'before', 'after'
1606
+ * - counterCache: Boolean to control updating of counter caches (if any)
1602
1607
* @param array $fieldList List of fields to allow to be written
1603
1608
* @return mixed On success Model::$data if its not empty or true, false on failure
1604
1609
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html
1605
1610
*/
1606
1611
public function save ($ data = null , $ validate = true , $ fieldList = array ()) {
1607
- $ defaults = array ('validate ' => true , 'fieldList ' => array (), 'callbacks ' => true );
1612
+ $ defaults = array (
1613
+ 'validate ' => true , 'fieldList ' => array (),
1614
+ 'callbacks ' => true , 'counterCache ' => true
1615
+ );
1608
1616
$ _whitelist = $ this ->whitelist ;
1609
1617
$ fields = array ();
1610
1618
@@ -1738,7 +1746,7 @@ public function save($data = null, $validate = true, $fieldList = array()) {
1738
1746
}
1739
1747
}
1740
1748
1741
- if ($ success && !empty ($ this ->belongsTo )) {
1749
+ if ($ success && $ options [ ' counterCache ' ] && !empty ($ this ->belongsTo )) {
1742
1750
$ this ->updateCounterCache ($ cache , $ created );
1743
1751
}
1744
1752
}
@@ -2019,7 +2027,9 @@ protected function _prepareUpdateFields($data) {
2019
2027
* 'AssociatedModel' => array('field', 'otherfield')
2020
2028
* )
2021
2029
* }}}
2022
- * - deep: see saveMany/saveAssociated
2030
+ * - deep: See saveMany/saveAssociated
2031
+ * - callbacks: See Model::save()
2032
+ * - counterCache: See Model::save()
2023
2033
*
2024
2034
* @param array $data Record data to save. This can be either a numerically-indexed array (for saving multiple
2025
2035
* records of the same type), or an array indexed by association name.
@@ -2055,6 +2065,8 @@ public function saveAll($data = array(), $options = array()) {
2055
2065
* Should be set to false if database/table does not support transactions.
2056
2066
* - fieldList: Equivalent to the $fieldList parameter in Model::save()
2057
2067
* - deep: If set to true, all associated data will be saved as well.
2068
+ * - callbacks: See Model::save()
2069
+ * - counterCache: See Model::save()
2058
2070
*
2059
2071
* @param array $data Record data to save. This should be a numerically-indexed array
2060
2072
* @param array $options Options to use when saving record data, See $options above.
@@ -2155,9 +2167,9 @@ public function validateMany(&$data, $options = array()) {
2155
2167
*
2156
2168
* #### Options
2157
2169
*
2158
- * - ` validate` Set to `false` to disable validation, `true` to validate each record before saving,
2170
+ * - validate: Set to `false` to disable validation, `true` to validate each record before saving,
2159
2171
* 'first' to validate *all* records before any are saved(default),
2160
- * - ` atomic` If true (default), will attempt to save all records in a single transaction.
2172
+ * - atomic: If true (default), will attempt to save all records in a single transaction.
2161
2173
* Should be set to false if database/table does not support transactions.
2162
2174
* - fieldList: Equivalent to the $fieldList parameter in Model::save().
2163
2175
* It should be an associate array with model name as key and array of fields as value. Eg.
@@ -2168,6 +2180,8 @@ public function validateMany(&$data, $options = array()) {
2168
2180
* )
2169
2181
* }}}
2170
2182
* - deep: If set to true, not only directly associated data is saved, but deeper nested associated data as well.
2183
+ * - callbacks: See Model::save()
2184
+ * - counterCache: See Model::save()
2171
2185
*
2172
2186
* @param array $data Record data to save. This should be an array indexed by association name.
2173
2187
* @param array $options Options to use when saving record data, See $options above.
0 commit comments