如何使用doctrine 1.2找到特定的相关对象

时间:2010-10-03 19:39:13

标签: php doctrine

来自doctrine 1.2手册的这个代码示例为我提供了一个phonenumber和areacode:

$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'];

是否可以使用areacode = 123获取特定的phonenumber而不循环Phonenumbers []?

1 个答案:

答案 0 :(得分:1)

试试这个:

$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'];