/** * afterSave * * @param Model $model * @param boolean $created * @return void */ public function afterSave(Model $model, $created) { if (!$created) { $parent = $model->parentNode(); $parent = $model->node($parent); $node = $model->node(); $aro = $node[0]; $aro['Aro']['parent_id'] = $parent[0]['Aro']['id']; $model->Aro->save($aro); } }
/** * Creates a new ARO/ACO node bound to this record * * @param Model $model Model using this behavior. * @param bool $created True if this is a new record * @param array $options Options passed from Model::save(). * * @return void */ public function afterSave(Model $model, $created, $options = array()) { $types = $this->_typeMaps[$this->settings[$model->name]['type']]; if (!is_array($types)) { $types = array($types); } foreach ($types as $type) { $parent = $model->parentNode($type); if (!empty($parent)) { $parent = $this->node($model, $parent, $type); } $data = array('parent_id' => isset($parent[0][$type]['id']) ? $parent[0][$type]['id'] : NULL, 'model' => $model->name, 'foreign_key' => $model->id); if (!$created) { $node = $this->node($model, NULL, $type); $data['id'] = isset($node[0][$type]['id']) ? $node[0][$type]['id'] : NULL; } $model->{$type}->create(); $model->{$type}->save($data); } }