|
@@ -97,7 +97,7 @@ class SoftDeleteBehavior extends ModelBehavior {
|
|
|
|
|
|
|
|
foreach ($fields as $flag => $date) {
|
|
foreach ($fields as $flag => $date) {
|
|
|
if ($runtime === true || $flag === $runtime) {
|
|
if ($runtime === true || $flag === $runtime) {
|
|
|
- if (!in_array($flag, $conditions) && !in_array($model->name . '.' . $flag, $conditions)) {
|
|
|
|
|
|
|
+ if (!in_array($flag, $conditions) && !in_array($model->alias . '.' . $flag, $conditions)) {
|
|
|
$query['conditions'][$model->alias . '.' . $flag] = false;
|
|
$query['conditions'][$model->alias . '.' . $flag] = false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -200,7 +200,8 @@ class SoftDeleteBehavior extends ModelBehavior {
|
|
|
$model->set($model->primaryKey, $id);
|
|
$model->set($model->primaryKey, $id);
|
|
|
$options = array(
|
|
$options = array(
|
|
|
'validate' => false,
|
|
'validate' => false,
|
|
|
- 'fieldList' => array_keys($data)
|
|
|
|
|
|
|
+ 'fieldList' => array_keys($data),
|
|
|
|
|
+ 'counterCache' => false
|
|
|
);
|
|
);
|
|
|
$result = $model->save(array($model->alias => $data), $options);
|
|
$result = $model->save(array($model->alias => $data), $options);
|
|
|
$this->softDelete($model, $runtime);
|
|
$this->softDelete($model, $runtime);
|
|
@@ -392,39 +393,23 @@ class SoftDeleteBehavior extends ModelBehavior {
|
|
|
protected function _getCounterCacheKeys(Model $model, $id) {
|
|
protected function _getCounterCacheKeys(Model $model, $id) {
|
|
|
$keys = array();
|
|
$keys = array();
|
|
|
if (!empty($model->belongsTo)) {
|
|
if (!empty($model->belongsTo)) {
|
|
|
- foreach ($model->belongsTo as $assoc) {
|
|
|
|
|
- if (empty($assoc['counterCache'])) {
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ $fields = array();
|
|
|
|
|
+ foreach ($model->belongsTo as $alias => $assoc) {
|
|
|
|
|
+ if (!empty($assoc['counterCache']) && isset($assoc['foreignKey']) && is_string($assoc['foreignKey'])) {
|
|
|
|
|
+ $fields[$alias] = $assoc['foreignKey'];
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ if (!empty($fields)) {
|
|
|
$keys = $model->find('first', array(
|
|
$keys = $model->find('first', array(
|
|
|
- 'fields' => $this->_collectForeignKeys($model),
|
|
|
|
|
|
|
+ 'fields' => $fields,
|
|
|
'conditions' => array($model->alias . '.' . $model->primaryKey => $id),
|
|
'conditions' => array($model->alias . '.' . $model->primaryKey => $id),
|
|
|
'recursive' => -1,
|
|
'recursive' => -1,
|
|
|
'callbacks' => false
|
|
'callbacks' => false
|
|
|
));
|
|
));
|
|
|
- break;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return $keys;
|
|
return $keys;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Collects foreign keys from `belongsTo` associations.
|
|
|
|
|
- *
|
|
|
|
|
- * @param Model $model
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- protected function _collectForeignKeys(Model $model) {
|
|
|
|
|
- $result = array();
|
|
|
|
|
-
|
|
|
|
|
- foreach ($model->belongsTo as $assoc => $data) {
|
|
|
|
|
- if (isset($data['foreignKey']) && is_string($data['foreignKey'])) {
|
|
|
|
|
- $result[$assoc] = $data['foreignKey'];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|