/**
  * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using
  * _add_relation_to because you don't have to specify what type of model you're
  * associating it with
  * @param EE_Base_Class $object
  * @param boolean $save
  * @return boolean if $save=true, NULL is $save=false
  */
 function set_object($object, $save = TRUE)
 {
     if ($object instanceof EE_Base_Class) {
         $this->set_OBJ_type($object->get_model()->get_this_model_name());
         $this->set_OBJ_ID($object->ID());
     } else {
         $this->set_OBJ_type(NULL);
         $this->set_OBJ_ID(NULL);
     }
     if ($save) {
         return $this->save();
     } else {
         return NULL;
     }
 }
 /**
  * Checks all the relations that throw error messages when there are blocking related objects
  * for related model objects. If there are any related model objects on those relations,
  * adds an EE_Error, and return true
  * @param EE_Base_Class|int $this_model_obj_or_id
  * @param EE_Base_Class $ignore_this_model_obj a model object like 'EE_Event', or 'EE_Term_Taxonomy', which should be ignored when
  * determining whether there are related model objects which block this model object's deletion. Useful
  * if you know A is related to B and are considering deleting A, but want to see if A has any other objects
  * blocking its deletion before removing the relation between A and B
  * @return boolean
  */
 public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null)
 {
     //first, if $ignore_this_model_obj was supplied, get its model
     if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
         $ignored_model = $ignore_this_model_obj->get_model();
     } else {
         $ignored_model = null;
     }
     //now check all the relations of $this_model_obj_or_id and see if there
     //are any related model objects blocking it?
     $is_blocked = false;
     foreach ($this->_model_relations as $relation_name => $relation_obj) {
         if ($relation_obj->block_delete_if_related_models_exist()) {
             //if $ignore_this_model_obj was supplied, then for the query
             //on that model needs to be told to ignore $ignore_this_model_obj
             if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
                 $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
             } else {
                 $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
             }
             if ($related_model_objects) {
                 EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
                 $is_blocked = true;
             }
         }
     }
     return $is_blocked;
 }
 /**
  *
  * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct
  * @param mixed $message array|string of the message you want to record
  * @param EE_Base_Class $related_model_obj
  * @return EE_Change_Log
  */
 public function log($log_type, $message, $related_model_obj)
 {
     if ($related_model_obj instanceof EE_Base_Class) {
         $obj_id = $related_model_obj->ID();
         $obj_type = $related_model_obj->get_model()->get_this_model_name();
     } else {
         $obj_id = NULL;
         $obj_type = NULL;
     }
     $log = EE_Change_Log::new_instance(array('LOG_type' => $log_type, 'LOG_message' => $message, 'OBJ_ID' => $obj_id, 'OBJ_type' => $obj_type));
     $log->save();
     return $log;
 }