在redbeanphp中查询多对多关系
我有两个表,分别是“user”和“estate”,我用此代码在这些表之间建立了许多关系:在redbeanphp中查询多对多关系,php,mysql,redbean,Php,Mysql,Redbean,我有两个表,分别是“user”和“estate”,我用此代码在这些表之间建立了许多关系: $user->link("estatetrans", (array("trtype" => $trtype, "indate" => time())))->estate = $estate; $trans = R::findAll("estatetrans", "users_id=:uid and trtype=:trt" , array("uid"=>$userId , "
$user->link("estatetrans", (array("trtype" => $trtype, "indate" => time())))->estate = $estate;
$trans = R::findAll("estatetrans", "users_id=:uid and trtype=:trt" , array("uid"=>$userId , "trt"=>$trtype)) ;
$estates = array() ;
foreach ($trans as $tr)
{
array_push($estates, $tr->estate) ;
}
“estaterans”是包含这两个表之间关系的表的名称:
现在我想通过过滤trtype列来查询“estaterans”表
我使用以下代码执行此操作:
$user->link("estatetrans", (array("trtype" => $trtype, "indate" => time())))->estate = $estate;
$trans = R::findAll("estatetrans", "users_id=:uid and trtype=:trt" , array("uid"=>$userId , "trt"=>$trtype)) ;
$estates = array() ;
foreach ($trans as $tr)
{
array_push($estates, $tr->estate) ;
}
但我知道这不是一个完美的好校长。
我如何通过redbeanphp方法完成这项工作?redbeanphp的方法是使用sharedList而不是findAll,例如:
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现在包含由estate_transaction.type列过滤的事务
请注意,如果您想要更高级的解决方案,也可以重命名链接表
干杯
加博