2009-12-30 48 views
0

我有一個簡單的原則代碼:主義問題JOIN和WHERE

 
$dql = Doctrine_Query::create() 
     ->select('u.ident, u.username, u.email') 
     ->from('Users u, u.Attributes ua'); 
if ($query) { 
    $dql->where('u.username LIKE ?', "%$query%") 
    ->orWhere('u.name LIKE ?', "%$query%") 
    ->orWhere('u.email LIKE ?', "%$query%"); 
} 
$dql->offset($start)->limit($count); 
$users = $dql->execute(); 

隨着探查,我發現,這種理論運行此爲兩個單獨的查詢:

 
SELECT DISTINCT e3.ident FROM users e3 
LEFT JOIN userpolicies e4 ON e3.ident = e4.user_id 
WHERE e3.username LIKE ? OR e3.name LIKE ? OR e3.email LIKE ? LIMIT 20 

Params: 
Array 
(
    [0] => %fam% 
    [1] => %fam% 
    [2] => %fam% 
) 

 
SELECT e.ident AS e__ident, e.username AS e__username, e.email AS e__email FROM users e 
LEFT JOIN userpolicies e2 ON e.ident = e2.user_id 
WHERE e.ident IN ('2', '40', '42', '44', '52', '53', '54', '55', '56', '58', '60', '61', '62', '64', '65', '66', '68', '70', '74', '82') AND e.username LIKE ? OR e.name LIKE ? OR e.email LIKE ? 

Params: 
Array 
(
    [0] => %fam% 
    [1] => %fam% 
    [2] => %fam% 
) 

這不正是我所想的,因爲第二個查詢甚至在t之後第二次應用WHERE條件他在第一個查詢中選擇了與'Users'匹配的行(即,第二個查詢應該以WHERE e.ident IN()停止)。這是我的錯誤還是學說的預期行爲?我使用的是教條v1.1.6。

回答

2

好吧,看起來這個問題在Doctrine 1.2版中得到修復。切換到它現在:)對不起,麻煩,夥計們。