diff options
author | Kevin Chabowski <kevin@kch42.de> | 2012-02-04 00:00:01 +0100 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2012-02-04 00:00:01 +0100 |
commit | 4e0297c5eefaa52115171ebd158634a945eb9048 (patch) | |
tree | fa7ddaec6c230068038b2ab6151f51c627db55fa | |
parent | f97e6364d19d4395034df9e99d80588b741600c4 (diff) | |
download | ratatoeskr-cms-4e0297c5eefaa52115171ebd158634a945eb9048.tar.gz ratatoeskr-cms-4e0297c5eefaa52115171ebd158634a945eb9048.tar.bz2 ratatoeskr-cms-4e0297c5eefaa52115171ebd158634a945eb9048.zip |
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.
-rw-r--r-- | ratatoeskr/sys/models.php | 11 |
1 files 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)) |