Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use key values not their element id's
  • Loading branch information
voidet committed Feb 17, 2011
1 parent 50b51e5 commit 85c5eed
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions models/behaviors/tag_time.php
Expand Up @@ -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;
}
}
Expand All @@ -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);
}

}

?>
}

0 comments on commit 85c5eed

Please sign in to comment.