From 4e0297c5eefaa52115171ebd158634a945eb9048 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 4 Feb 2012 00:00:01 +0100 Subject: Fixed two bugs in the Article class. 1. Article::set_tags now actually saves tag relations... 2. Article::by_multi() filters out duplicates that were a result from the join with the `PREFIX_article_tag_relations` table. --- ratatoeskr/sys/models.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php index a4d7ebf..cde5cc3 100644 --- a/ratatoeskr/sys/models.php +++ b/ratatoeskr/sys/models.php @@ -2422,8 +2422,15 @@ LEFT OUTER JOIN `PREFIX_article_tag_relations` `c` ON `a`.`id` = `c`.`article` WHERE " . implode(" AND ", $subqueries) . " $sorting"); $rows = array(); + $fetched_ids = array(); while($sqlrow = mysql_fetch_assoc($result)) - $rows[] = $sqlrow; + { + if(!in_array($sqlrow["id"], $fetched_ids)) + { + $rows[] = $sqlrow; + $fetched_ids[] = $sqlrow["id"]; + } + } if($count !== NULL) $rows = array_slice($rows, 0, $count); @@ -2516,7 +2523,7 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); $articleid = $this->id; /* So we just need to fire one query instead of count($this->tags) queries. */ - if(!empty($this->tags)) + if(!empty($tags)) qdb( "INSERT INTO `PREFIX_article_tag_relations` (`article`, `tag`) VALUES " . implode(",", array_map(function($tag) use ($articleid){ return qdb_fmt("(%d, %d)", $articleid, $tag->get_id()); }, $tags)) -- cgit v1.2.3-54-g00ecf