2011-01-28 56 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(); 

但是未在指定插件標記和內容之間的關係,所以主義拋出一個「未知關係別名」異常。

編輯

我嘗試使用功能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

Got it!我想過下載插件撇號和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. 創建它們之間的關係
  2. 實現一個CountCache行爲

所以在這種情況下,你可以很容易地標記程序工作。