Skip to content

Commit

Permalink
Fix some database calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed Dec 7, 2009
1 parent 5a7449f commit 2132c9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/tag/controllers/admin_tags.php
Expand Up @@ -51,7 +51,7 @@ public function delete($id) {
$form = tag::get_delete_form($tag);
if ($form->validate()) {
$name = $tag->name;
Database::instance()->delete("items_tags", array("tag_id" => "$tag->id"));
db::build()->delete("items_tags")->where("tag_id", "=", $tag->id)->execute();
$tag->delete();
message::success(t("Deleted tag %tag_name", array("tag_name" => $name)));
log::success("tags", t("Deleted tag %tag_name", array("tag_name" => $name)));
Expand Down
19 changes: 16 additions & 3 deletions modules/tag/models/tag.php
Expand Up @@ -63,13 +63,21 @@ public function items_count($type=null) {
public function save() {
$db = Database::instance();
$related_item_ids = array();
foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) {
foreach (db::build()
->select("item_id")
->from("items_tags")
->where("tag_id", "=", $this->id)
->execute() as $row) {
$related_item_ids[$row->item_id] = 1;
}

$result = parent::save();

foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) {
foreach (db::build()
->select("item_id")
->from("items_tags")
->where("tag_id", "=", $this->id)
->execute() as $row) {
$related_item_ids[$row->item_id] = 1;
}

Expand All @@ -89,7 +97,12 @@ public function save() {
public function delete() {
$related_item_ids = array();
$db = Database::Instance();
foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) {

foreach (db::build()
->select("item_id")
->from("items_tags")
->where("tag_id", "=", $this->id)
->execute() as $row) {
$related_item_ids[$row->item_id] = 1;
}

Expand Down

0 comments on commit 2132c9a

Please sign in to comment.