/**
  * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is sometime delayed if the object is created/saved first by the autosave)
  *
  * @param  EE_Base_Class $this_obj
  * @param  EE_Base_Class $other_obj
  * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
  * @return EE_Base_Class. ($other_obj);
  * @throws \EE_Error
  */
 protected function _check_for_revision($this_obj, $other_obj, $remove_relation = FALSE)
 {
     $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
     //now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
     if ($this_obj->post_type() === 'revision') {
         //first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
         $parent_evt_id = $this_obj->parent();
         /*var_dump($parent_evt_id);
         		var_dump($this_obj);
         		var_dump($other_obj);/**/
         if (!empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
             //let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
             $has_parent_obj = $this->get_other_model()->get_one(array(array($this->_parent_pk_relation_field => $other_obj->ID(), $this->_primary_cpt_field => $this_obj->ID())));
             if ($has_parent_obj) {
                 //this makes sure the update on the current obj happens to the revision's row NOT the parent row.
                 $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
                 $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
                 $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
                 if (!$remove_relation) {
                     $other_obj->save();
                     return array($other_obj);
                 } elseif ($remove_relation && !$this->_blocking_delete) {
                     $other_obj->delete();
                     $other_obj->set($this->_parent_pk_relation_field, NULL, true);
                     return array($other_obj);
                 }
             } else {
                 $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
                 $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
                 $other_obj->set($pk_on_related_model, NULL, true);
                 //ensure we create a new row for the autosave with parent id the same as the incoming ID.
                 $other_obj->save();
                 //make sure we insert.
                 return array($other_obj);
             }
         }
         //var_dump('what makes it here');
         //var_dump($other_obj);
         //the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
         //the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
     } else {
         //we only need to do the below IF this is not a remove relation
         if (!$remove_relation) {
             //okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
             //the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
             $existing_other_obj = $this->get_other_model()->get_one_by_ID($other_obj->ID());
             $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : NULL;
             if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
                 //yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
                 $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
                 $other_obj->save();
                 //now create a new other_obj and fill with details from existing object
                 $new_obj = $other_obj;
                 $new_obj->set($this->_primary_cpt_field, $potential_revision_id);
                 $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
                 $new_obj->set($pk_on_related_model, NULL);
                 $new_obj->save();
                 return array($new_obj);
             }
         }
     }
     return $other_obj;
 }