来自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 []?
答案 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'];