php - query over many to many relationship in redbeanphp -
i have 2 tables "user" , "estate" , make many-many relation between table code :
$user->link("estatetrans", (array("trtype" => $trtype, "indate" => time())))->estate = $estate;
"estatetrans" name of table contain relation between these 2 table :
now want query on "estatetrans" table filtering on trtype column.
i action using code :
$trans = r::findall("estatetrans", "users_id=:uid , trtype=:trt" , array("uid"=>$userid , "trt"=>$trtype)) ; $estates = array() ; foreach ($trans $tr) { array_push($estates, $tr->estate) ; }
but know not perfect , principal. how can work redbeanphp methods?
the redbeanphp way use sharedlist instead of findall, example, this:
list($e, $t) = r::dispenseall('estate,transaction'); $e ->link('estate_transaction',['type'=>'auction']) ->transaction = $t; r::store($e); $e = r::findone('estate'); $x = $e ->withcondition(' estate_transaction.type = ? ',['auction']) ->sharedtransaction;
$x contains transactions, filtered estate_transaction.type column.
note can rename link table if want fancier solution.
cheers gabor
Comments
Post a Comment