summaryrefslogtreecommitdiff
path: root/modules/tag/models
diff options
context:
space:
mode:
authorNathan Kinkade <nkinkade@nkinka.de>2011-01-14 01:12:32 +0000
committerNathan Kinkade <nkinkade@nkinka.de>2011-01-14 01:12:32 +0000
commit2898fe3b82ce10d045dd2c274a3290bacf209a00 (patch)
tree5aced91bb92d8c9136cabf60ebc918248328907a /modules/tag/models
parent47cbef684d41a4d51a9848091997e10b909abf32 (diff)
parente4a43c99e421c830e569eaae6294286ed51e0ad8 (diff)
Git pull from devel line.
Diffstat (limited to 'modules/tag/models')
-rw-r--r--modules/tag/models/tag.php16
1 files changed, 13 insertions, 3 deletions
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php
index 44a4c904..06620ae2 100644
--- a/modules/tag/models/tag.php
+++ b/modules/tag/models/tag.php
@@ -20,6 +20,15 @@
class Tag_Model_Core extends ORM {
protected $has_and_belongs_to_many = array("items");
+ public function __construct($id=null) {
+ parent::__construct($id);
+
+ if (!$this->loaded()) {
+ // Set reasonable defaults
+ $this->count = 0;
+ }
+ }
+
/**
* Return all viewable items associated with this tag.
* @param integer $limit number of rows to limit result to
@@ -70,11 +79,12 @@ class Tag_Model_Core extends ORM {
$related_item_ids[$row->item_id] = 1;
}
+ $added = array_diff($this->changed_relations["items"], $this->object_relations["items"]);
+ $removed = array_diff($this->object_relations["items"], $this->changed_relations["items"]);
if (isset($this->changed_relations["items"])) {
- $changed = array_merge(
- array_diff($this->changed_relations["items"], $this->object_relations["items"]),
- array_diff($this->object_relations["items"], $this->changed_relations["items"]));
+ $changed = array_merge($added, $removed);
}
+ $this->count = count($this->object_relations["items"]) + count($added) - count($removed);
$result = parent::save();