2015-06-14 62 views
0

一对多的关系我有两个表分别是“用户”和“地产”我可以把这个代码的那些表之间的多对多关系:查询过许多在redbeanphp

$user->link("estatetrans", (array("trtype" => $trtype, "indate" => time())))->estate = $estate; 

“estatetrans “是包含这两个表之间的关系表的名称:

现在我想对查询‘由trtype列筛选estatetrans’表。

我这样做使用此代码这个动作:

$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方法来完成这项工作?

回答

1

的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柱进行过滤。

请注意,如果您想要更出色的解​​决方案,您还可以重命名链接表。

欢呼 的Gabor

+0

你是我的英雄........亲爱的Gabor –