php - Finding a specific row in a PropelCollection -
i have 2 tables. 1 orders, , prefs. tables this:
order:
+----------+---------------+------------+ | orderid | ordernumber | clientid | +----------+---------------+------------+ | 1 | abc123 | 2 | | 2 | orderx | 7 | | 3 | joe9 | 2 | | 4 | order4 | 2 | +----------+---------------+------------+
orderpref
+----------+----------+-------------+ | orderid | prefid | prefvalue | +----------+----------+-------------+ | 1 | 1 | $100 | | 1 | 2 | 123 | | 1 | 3 | $35 | | 2 | 1 | $600 | | 2 | 2 | 876 | | 2 | 3 | $44 | +----------+----------+-------------+
what want each order, prefvalue
specific prefid
. currently, doing:
$orders = ordersquery::create()->filterbyclientid(2)->find(); foreach($orders $o){ $prefs = $o->getorderprefs(); foreach($prefs $p){ if($p->getprefid() === 2){ echo $p->getprefvalue(); break; } } }
this works, there needs better way 1 row want each order without looping through prefs.
i know doesn't work, there this?
$orders = ordersquery::create()->filterbyclientid(2)->find(); foreach($orders $o){ // doesn't work, there short way this? echo $o->getorderprefs()->filterbyprefid(2)->getprefvalue(); }
i reading docs , found ->search()
method, don't know how use it.
$orders = ordersquery::create()->filterbyclientid(2)->find(); foreach($orders $o){ // how can search row prefid want? echo $o->getorderprefs()->search()->getprefvalue(); }
looking @ old propel stuff i've written, i'm guessing like:
$prefvalue = ordersquery::create()-> joinorderpref()-> where('orderpref.prefid = ?', $prefid)-> filterbyclientid($clientid)-> select('orderpref.prefvalue')-> find() ;
the issue need specific column (reference).
for these chainable queries, view auto-completing editor pretty mandatory - remembering syntax nigh-on impossible without it.
Comments
Post a Comment