开发者

how to find a specific related object with doctrine 1.2

this code example from doctrine开发者_运维技巧 1.2 manual gives me one phonenumber and areacode for the user:

$q = Doctrine_Query::create()
->from('User u')
->leftJoin('u.Phonenumbers p')
->where('u.id = ?', 1);

$user = $q->fetchOne();

echo $user->Phonenumbers[0]['phonenumber'];
echo $user->Phonenumbers[0]['areacode'];

Is it possible to get the specific phonenumber with areacode = 123 without looping Phonenumbers[]?


try this:

$q = Doctrine_Query::create()
->from('User u')
->leftJoin('u.Phonenumbers p')
->where('u.id = ? AND p.areacode = ?', 1,$areacode);

$user = $q->fetchOne();

echo $user->Phonenumbers[0]['phonenumber'];
echo $user->Phonenumbers[0]['areacode'];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜