简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM