/** * Deletes the current record. * * This method deletes the current record and also all linked records. * * Example: * ```php * // deletes the current record * $r->delete(); * * // deletes the current record and the linked record * // 'table1' is linked to 'table0' by the 'table1[id = table1_id]' condition * $r->delete("table1[id = table1_id]"); * * // or more briefly * $r->delete("table1"); * * // deletes the current record and a list of linked records * $r->delete("table1", "table2", "table3"); * * // creates a new record and, after that, deletes the * // linked records (table1, table2 and table3) * $r = new DbRecord($db, "table0"); * $r->save([ * "label" => "xxx", * "table1.label" => "aaa", * "table2.label" => "bbb", * "table3.label" => "ccc" * ]); * $r->delete(); * ``` * * @param string[] $tablePaths List of table paths * * @return void */ public function delete($tablePaths = []) { if (count($tablePaths) > 0) { // registers tables and deletes $this->_tables = []; $this->_columns = []; foreach ($tablePaths as $tablePath) { $this->regTable($tablePath); } $this->delete(); } else { // first deletes linked records foreach ($this->_tables as $table) { $record = $table->getRecord(); $record->delete(); } // and finally deletes the current record $this->_db->exec($this->_getDeleteStatement()); $this->_isUpdated = true; } }
/** * Deletes the current record. * * @return void */ public function delete() { $this->_db->exec($this->_getDeleteStatement()); $this->_isUpdated = true; }