/** * Automatically finds the related model info from the form, if present, and * save the relations indicated * @type string $relation_name * @return bool * @throws EE_Error */ protected function _save_related_info($relation_name) { $relation_obj = $this->_model->related_settings_for($relation_name); if ($relation_obj instanceof EE_Belongs_To_Relation) { //there is just a foreign key on this model pointing to that one $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); } elseif ($relation_obj instanceof EE_Has_Many_Relation) { //then we want to consider all of its currently-related things. //if they're in this list, keep them //if they're not in this list, remove them //and lastly add all the new items throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); } elseif ($relation_obj instanceof EE_HABTM_Relation) { //delete everything NOT in this list $normalized_input_value = $this->get_input_value($relation_name); if ($normalized_input_value && is_array($normalized_input_value)) { $where_query_params = array($relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value)); } else { $where_query_params = array(); } $this->_model_object->_remove_relations($relation_name, $where_query_params); foreach ($normalized_input_value as $id) { $this->_model_object->_add_relation_to($id, $relation_name); } } return TRUE; }