diff --git a/models/behaviors/tag_time.php b/models/behaviors/tag_time.php index b5796c4..805f565 100644 --- a/models/behaviors/tag_time.php +++ b/models/behaviors/tag_time.php @@ -26,7 +26,7 @@ function beforeSave(&$Model) { extract($this->settings[$Model->alias]); if (!empty($tagIds)) { - foreach($tagIds as $tagId) { + foreach($tagIds as $key => $tagId) { $Model->data[$assoc_model][$assoc_model][] = $tagId; } } @@ -41,24 +41,20 @@ function _getTagIds(&$Model) { if (Set::filter($tags)) { foreach ($tags as $tag) { $tag = strtolower(trim($tag)); - $existingTag = $Model->{$assoc_model}->find('first', array( 'conditions' => array($assoc_model.'.'.$tag_field => $tag), 'recursive' => -1 )); - if (!$existingTag) { + if (empty($existingTag)) { $Model->{$assoc_model}->saveField($tag_field, $tag); $tagIds[] = $Model->{$assoc_model}->id; } else { $tagIds[] = $existingTag[$assoc_model]['id']; } } - - return array_unique($tagIds); } + return array_unique($tagIds); } -} - -?> \ No newline at end of file +} \ No newline at end of file