$config); } $settings = array_merge($this->_defaults, $config); if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) { $data = $Model->getAssociated($settings['scope']); $this->settings[$Model->alias]['scopeForeignKey'] = $data['foreignKey']; } } /** * Before save method. Called before all saves * * Overriden to transparently manage setting the lft and rght fields if and only if the parent field is included in the * parameters to be saved. For newly created nodes with NO parent the left and right field values are set directly by * this method bypassing the setParent logic. * * @since 1.2 * @param AppModel $Model Model instance * @return boolean true to continue, false to abort the save * @access public */ function beforeSave(&$Model) { // Correct the scope of the behavior settings if required. $this->_addScopeForeignKey($Model); parent::beforeSave($Model); } /** * add a foreign ID scope to the model settings. * * @param AppModel $Model Model instance * @return true on success, false on failure * @access protected */ function _addScopeForeignKey(&$Model) { if (!isset($this->settings[$Model->alias]['scopeForeignKey'])) { return false; } if (!isset($Model->data[$Model->alias][$this->settings[$Model->alias]['scopeForeignKey']])) { return false; } $this->settings[$Model->alias]['scope'] = array($Model->alias . '.' . $this->settings[$Model->alias]['scopeForeignKey'] => $Model->data[$Model->alias][$this->settings[$Model->alias]['scopeForeignKey']]); return true; } } ?>