/**
  * Remove a single representation from the currently loaded object. Note that the representation will be removed from the database completely, so if it is also linked to other items it will be removed from them as well.
  *
  * @param int $pn_representation_id The representation_id of the representation to remove
  * @param array $pa_options Options are passed through to BaseMode::delete()
  * @return bool True if delete succeeded, false if there was an error. You can get the error messages by calling getErrors() on the instance.
  */
 public function removeRepresentation($pn_representation_id, $pa_options = null)
 {
     if (!$this->getPrimaryKey()) {
         return null;
     }
     $va_path = array_keys($this->getAppDatamodel()->getPath($this->tableName(), 'ca_object_representations'));
     if (is_array($va_path) && sizeof($va_path) == 3) {
         $vs_rel_table = $va_path[1];
         if ($t_rel = $this->getAppDatamodel()->getInstanceByTableName($vs_rel_table)) {
             if ($this->inTransaction()) {
                 $t_rel->setTransaction($this->getTransaction());
             }
             if ($t_rel->load(array($this->primaryKey() => $this->getPrimaryKey(), 'representation_id' => $pn_representation_id))) {
                 $t_rel->setMode(ACCESS_WRITE);
                 $t_rel->delete();
                 if ($t_rel->numErrors()) {
                     $this->errors = array_merge($this->errors, $t_rel->errors());
                     return false;
                 }
             }
         }
     }
     $t_rep = new ca_object_representations();
     if ($this->inTransaction()) {
         $t_rep->setTransaction($this->getTransaction());
     }
     if (!$t_rep->load($pn_representation_id)) {
         $this->postError(750, _t("Representation id=%1 does not exist", $pn_representation_id), "RepresentableBaseModel->removeRepresentation()");
         return false;
     } else {
         //
         // Only delete the related representation if nothing else is related to it
         //
         $va_rels = $t_rep->hasRelationships();
         if (is_array($va_rels) && isset($va_rels['ca_object_representation_labels'])) {
             // labels don't count as relationships in this case
             unset($va_rels['ca_object_representation_labels']);
         }
         if (is_array($va_rels) && isset($va_rels['ca_objects_x_object_representations']) && $va_rels['ca_objects_x_object_representations'] < 1) {
             unset($va_rels['ca_objects_x_object_representations']);
         }
         if (!is_array($va_rels) || sizeof($va_rels) == 0) {
             $t_rep->setMode(ACCESS_WRITE);
             $t_rep->delete(true, $pa_options);
             if ($t_rep->numErrors()) {
                 $this->errors = array_merge($this->errors, $t_rep->errors());
                 return false;
             }
         }
         // remove any replicated media
         if (is_array($va_replication_targets = $t_rep->getUsedMediaReplicationTargets('media'))) {
             foreach ($va_replication_targets as $vs_target => $va_target_info) {
                 $t_rep->removeMediaReplication('media', $vs_target, $t_rep->getMediaReplicationKey('media', $vs_target));
             }
         }
         return true;
     }
     return false;
 }