1

我正在使用插件将标签添加到数据库的内容中,并且在编写以下查询时遇到了一些困难:

我想要标记到至少一个已发布内容的标签列表,所以我尝试了:

$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));

但它仍然显示所有标签,以及奇怪的数字作为计数。

4

2 回答 2

0

I think it's a good practice to:

  1. Create a relation between them
  2. Implement a CountCache behavior

So in this case you can easily work with tagging routines.

于 2011-01-31T13:33:41.727 回答
0

知道了 !我想过下载 Apostrophe 插件并搜索getAllTagNameWithCount调用

    $q = Doctrine_Query::create()->from('Tagging tg, tg.Tag t, Content
c');
    $q->andWhere('c.id = tg.taggable_id and c.state_id = ?', 3);

    $this->tagsInOrder =
PluginTagTable::getAllTagNameWithCount($q,Array('model' => 'Content',
'sort_by_popularity' => true)); 
于 2011-02-07T08:59:02.857 回答