public function update($pa_options = null)
 {
     $vb_we_set_transaction = false;
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
     } else {
         $o_trans = new Transaction();
         $this->setTransaction($o_trans);
         $vb_we_set_transaction = true;
     }
     $o_db = $o_trans->getDb();
     list($vs_target_table, $vs_target_key) = $this->_getTarget();
     $vs_rel_table = $this->tableName();
     $t_target = $this->getAppDatamodel()->getInstanceByTableName($vs_target_table);
     $vn_target_id = $this->get($vs_target_key);
     if (!$t_target->load($vn_target_id)) {
         // invalid target
         $this->postError(720, _t("Related %1 does not exist", $t_target->getProperty('NAME_SINGULAR')), "BaseRepresentationRelationship->update()");
         return false;
     }
     if ($this->changed('is_primary')) {
         if (!$this->get('is_primary')) {
             // force is_primary to be set if no other represention is so marked
             // is there another rep for this object marked is_primary?
             $qr_res = $o_db->query("\n\t\t\t\t\t\tSELECT oxor.relation_id\n\t\t\t\t\t\tFROM {$vs_rel_table} oxor\n\t\t\t\t\t\tINNER JOIN ca_object_representations AS o_r ON o_r.representation_id = oxor.representation_id\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\toxor.{$vs_target_key} = ? AND oxor.is_primary = 1 AND o_r.deleted = 0 AND oxor.relation_id <> ?\n\t\t\t\t\t", (int) $vn_target_id, (int) $this->getPrimaryKey());
             if (!$qr_res->nextRow()) {
                 // nope - force one to be primary
                 //$this->set('is_primary', 1);
                 $qr_res = $o_db->query("\n\t\t\t\t\t\t\tSELECT oxor.relation_id\n\t\t\t\t\t\t\tFROM {$vs_rel_table} oxor\n\t\t\t\t\t\t\tINNER JOIN ca_object_representations AS o_r ON o_r.representation_id = oxor.representation_id\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\toxor.{$vs_target_key} = ? AND oxor.is_primary = 0 AND o_r.deleted = 0 AND oxor.relation_id <> ?\n\t\t\t\t\t\t\tORDER BY oxor.rank, oxor.relation_id\n\t\t\t\t\t\t", (int) $vn_target_id, (int) $this->getPrimaryKey());
                 if ($qr_res->nextRow()) {
                     $o_db->query("\n\t\t\t\t\t\t\t\tUPDATE {$vs_rel_table}\n\t\t\t\t\t\t\t\tSET is_primary = 1\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\trelation_id = ?\n\t\t\t\t\t\t\t", (int) $qr_res->get('relation_id'));
                     if (!($vb_rc = parent::update($pa_options))) {
                         if ($vb_we_set_transaction) {
                             $o_trans->rollbackTransaction();
                         }
                     } else {
                         if ($vb_we_set_transaction) {
                             $o_trans->commitTransaction();
                         }
                     }
                 }
             }
             return parent::update($pa_options);
         } else {
             // unset other reps is_primary field
             $o_db->query("\n\t\t\t\t\t\tUPDATE {$vs_rel_table}\n\t\t\t\t\t\tSET is_primary = 0\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t{$vs_target_key} = ?\n\t\t\t\t\t", (int) $vn_target_id);
             if (!($vb_rc = parent::update($pa_options))) {
                 if ($vb_we_set_transaction) {
                     $o_trans->rollbackTransaction();
                 }
             } else {
                 if ($vb_we_set_transaction) {
                     $o_trans->commitTransaction();
                 }
             }
             return $vb_rc;
         }
     } else {
         $vb_rc = parent::update($pa_options);
         if ($vb_we_set_transaction) {
             $o_trans->commitTransaction();
         }
         return $vb_rc;
     }
 }
 /**
  *
  */
 public function update($pa_options = null)
 {
     if (!$this->get('effective_date', array('getDirectDate' => true))) {
         $this->set('effective_date', $this->_getMovementDate());
         $this->set('source_info', $this->_getStorageLocationInfo());
     }
     return parent::update($pa_options);
 }