我正在使用插件将标签添加到数据库的内容中,并且在编写以下查询时遇到了一些困难:
我想要标记到至少一个已发布内容的标签列表,所以我尝试了:
$this->tagsNumber = Doctrine_Core::getTable('Tag')
->createQuery('t')
->select('t.name, count(tg.tag_id) as nbr')
->innerJoin('t.Tagging tg')
->innerJoin('Content c on c.id = tg.taggable_id')
->where('c.state = ?', 3)
->orderBy('nbr DESC, t.name')
->groupBy('tg.tag_id')
->execute();
但是插件中没有指定 Tagging 和 Content 之间的关系,因此 Doctrine 会抛出“未知关系别名”异常。
编辑
我尝试使用PluginTagTable.class.php中的函数:
$q = Doctrine_Query::create()
->select('tg.tag_id, t.name, COUNT(tg.id) AS t_count')
->from('Tagging tg, tg.Tag t, Content c on tg.model_id = c.id')
->where('c.state_id = ?', 3);
$this->etiquettesOrdre = PluginTagTable::getAllTagNameWithCount($q,Array('model' => 'Content', 'sort_by_popularity' => true));
但它仍然显示所有标签,以及奇怪的数字作为计数。