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'];
精彩评论