开发者

how to find a specific related object with doctrine 1.2

开发者 https://www.devze.com 2023-01-18 19:05 出处:网络
this code example from doctrine开发者_运维技巧 1.2 manual gives me one phonenumber and areacode for the user:

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

精彩评论

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

关注公众号