public function test_constructor() { $select = Jam_Query_Builder_Delete::factory('test_author'); $this->assertInstanceOf('Jam_Query_Builder_Delete', $select); $this->assertEquals(Jam::meta('test_author'), $select->meta()); $this->assertEquals('DELETE FROM `test_authors`', (string) $select); }
/** * Generate a query to remove models from the association (without deleting them), for specific ids * @param Jam_Model $model * @param array $ids * @return Database_Query */ public function remove_items_query(Jam_Model $model, array $ids) { switch ($this->delete_on_remove) { case TRUE: case Jam_Association::DELETE: foreach (Jam::all($this->foreign_model)->where_key($ids) as $item) { $item->delete(); } $query = NULL; break; case Jam_Association::ERASE: $query = Jam_Query_Builder_Delete::factory($this->foreign_model)->where(':primary_key', 'IN', $ids); if ($this->is_polymorphic()) { $query->value($this->polymorphic_key, NULL); } break; default: $query = Jam_Query_Builder_Update::factory($this->foreign_model)->where(':primary_key', 'IN', $ids)->value($this->foreign_key, NULL); if ($this->is_polymorphic()) { $query->value($this->polymorphic_key, NULL); } } return $query; }
/** * Generate a query to remove models from the association (without deleting them), for specific ids * @param Jam_Model $model * @param array $ids * @return Database_Query */ public function remove_items_query(Jam_Model $model, array $ids) { if (TRUE === $this->delete_on_remove or Jam_Association::DELETE === $this->delete_on_remove) { foreach (Jam::all($this->foreign_model)->where_key($ids) as $item) { $item->delete(); } $query = NULL; } elseif ($this->delete_on_remove === Jam_Association::ERASE) { $query = Jam_Query_Builder_Delete::factory($this->foreign_model)->where(':primary_key', 'IN', $ids); if ($this->is_polymorphic()) { $query->value($this->polymorphic_key, NULL); } } else { $query = Jam_Query_Builder_Update::factory($this->foreign_model)->where(':primary_key', 'IN', $ids)->value($this->foreign_key, NULL); if ($this->is_polymorphic()) { $query->value($this->polymorphic_key, NULL); } } return $query; }