| | 1460 | if($this->auto_delete_habtm) { |
| | 1461 | if(is_string($this->has_and_belongs_to_many)) { |
| | 1462 | $habtms = explode(",", $this->has_and_belongs_to_many); |
| | 1463 | foreach($habtms as $other_table_name) { |
| | 1464 | $this->delete_all_habtm_records(trim($other_table_name), $id); |
| | 1465 | } |
| | 1466 | } elseif(is_array($this->has_and_belongs_to_many)) { |
| | 1467 | foreach($this->has_and_belongs_to_many as $other_table_name => $values) { |
| | 1468 | $this->delete_all_habtm_records($other_table_name, $id); |
| | 1469 | } |
| | 1470 | } |
| | 1471 | } |
| 1572 | | $table_name = $this->get_join_table_name($this->table_name,$other_table_name); |
| 1573 | | $this_foreign_key = Inflector::singularize($this->table_name)."_id"; |
| 1574 | | $sql = "DELETE FROM $table_name WHERE $this_foreign_key = $this_foreign_value"; |
| 1575 | | //echo "delete_habtm_records: SQL: $sql<br>"; |
| 1576 | | $result = $this->query($sql); |
| 1577 | | if($this->is_error($result)) { |
| 1578 | | $this->raise($result->getMessage()); |
| 1579 | | } |
| | 1590 | $this->delete_all_habtm_records($other_table_name, $this_foreign_value); |
| | 1594 | } |
| | 1595 | |
| | 1596 | private function delete_all_habtm_records($other_table_name, $this_foreign_value) { |
| | 1597 | if($other_table_name && $this_foreign_value > 0) { |
| | 1598 | $habtm_table_name = $this->get_join_table_name($this->table_name,$other_table_name); |
| | 1599 | $this_foreign_key = Inflector::singularize($this->table_name)."_id"; |
| | 1600 | $sql = "DELETE FROM $habtm_table_name WHERE $this_foreign_key = $this_foreign_value"; |
| | 1601 | //echo "delete_all_habtm_records: SQL: $sql<br>"; |
| | 1602 | $result = $this->query($sql); |
| | 1603 | if($this->is_error($result)) { |
| | 1604 | $this->raise($result->getMessage()); |
| | 1605 | } |
| | 1606 | } |