$trtype-6ren">
gpt4 book ai didi

php - 在redbeanphp中查询多对多关系

转载 作者:行者123 更新时间:2023-11-29 07:35:56 26 4
gpt4 key购买 nike

我有两个表,分别是“user”和“estate”,我使用以下代码在这些表之间建立了多对关系:

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

"estatetrans" is name of table that contain relation between these two table :

现在我想通过过滤 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 方法完成这项工作?

最佳答案

RedBeanPHP 方法是使用共享列表而不是 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 列过滤的交易。

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

干杯嘉博

关于php - 在redbeanphp中查询多对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30829321/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com