2011-01-28 6 views
1

を書く:トラブル私は私のデータベースの内容にタグを追加するプラグインを使用している、と私は次のクエリを書くことでいくつかの困難を抱えているDQLクエリ

私がタグ付けされたタグのリストが欲しいです少なくとも一つの公開されたコンテンツに、私が試した:

$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(); 
しかし、タグ付けとコンテンツとの関係は、プラグインで指定されていないので、Doctrineは「未知の関係の別名」例外がスローされます。

EDIT

私は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)); 

しかし、それはまだ数など、すべてのタグ、そして奇妙な数字を示しています。

答えて

0

私はアポストロフィプラグインをダウンロードして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)); 
呼び出します
0

私はそれは良い習慣だと思うへ:

  1. したがって、この場合には、簡単にタグ付けルーチンで作業することができCountCache行動

を実装

  • 、それらの間の関係を作成します。

    関連する問題