Permalink
Browse files

Define `DetailableBehavior::$__data` and unset it post-operation.

  • Loading branch information...
jadb committed Feb 28, 2014
1 parent 14f01d9 commit 02c6ff97ba5d7c9a69efc6fd585d5771da25d710
Showing with 11 additions and 3 deletions.
  1. +11 −3 Model/Behavior/DetailableBehavior.php
@@ -29,6 +29,13 @@ class DetailableBehavior extends ModelBehavior {
*/
public $settings = array();
+/**
+ * Data holder. Used to bypass `Model::validateMany`.
+ *
+ * @var array
+ */
+ private $__data = array();
+
/**
* {@inheritdoc}
*/
@@ -106,8 +113,9 @@ public function afterSave(Model $Model, $created = false) {
$DetailModel = ClassRegistry::init($this->settings[$Model->alias]['alias']);
// Reset DetailModel data that was unset before validation.
- if (!empty($this->__dataToSave[$Model->alias])) {
- $Model->data[$DetailModel->alias] = $this->__dataToSave[$Model->alias];
+ if (!empty($this->__data[$Model->alias])) {
+ $Model->data[$DetailModel->alias] = $this->__data[$Model->alias];
+ unset($this->__data[$Model->alias]);
}
if ($created && empty($Model->data[$DetailModel->alias]) && false === $this->detailsCreateDefaults($Model)) {
@@ -127,7 +135,7 @@ public function beforeValidate(Model $Model) {
// Unset DetailModel data so it is not included in `Model::validateMany()`.
if (!empty($Model->data[$DetailModel->alias])) {
- $this->__dataToSave[$Model->alias] = $Model->data[$DetailModel->alias];
+ $this->__data[$Model->alias] = $Model->data[$DetailModel->alias];
unset($Model->data[$DetailModel->alias]);
}

0 comments on commit 02c6ff9

Please sign in to comment.