/** * Unlinks any ca_objects rows related to the currently loaded ca_object_lots record. Note that this does *not* * delete the related objects. It only removes their link to this lot. Note that on error, the database maybe left in * an inconsistent state where some objects are still linked to the lot. If you want to prevent this then wrap your * call to removeAllObjects in a transaction and rollback the transaction on error. * * @return boolean Returns true on success, false if there were errors. */ public function removeAllObjects() { if (!($vn_lot_id = $this->getPrimaryKey())) { return null; } $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\t\tSELECT object_id\n\t\t\t\tFROM ca_objects\n\t\t\t\tWHERE\n\t\t\t\t\tlot_id = ? AND deleted = 0\n\t\t\t", (int) $vn_lot_id); $t_object = new ca_objects(); if ($o_t = $this->getTransaction()) { $t_object->setTransaction($o_t); } $vb_errors = false; while ($qr_res->nextRow()) { if ($t_object->load($qr_res->get('object_id'))) { $t_object->setMode(ACCESS_WRITE); $t_object->set('lot_id', null); $t_object->update(); if ($t_object->numErrors()) { $this->errors = array_merge($this->errors, $t_object->errors); $vb_errors = true; } } } if ($t_object->inTransaction()) { $t_object->removeTransaction(true); } return !$vb_errors; // return true if no errors, false if errors }