[英]How can I query relational active record from table B with table A has two fields connect the table B's primary key?
每個人。
我需要為我的應用程序查詢交換規則記錄,規則表如下:
並有另一個像這樣的表:
我需要得到這樣的數據結構:
array(4) {
[0] => array(6) {
["id"] => int(4)
["pay_goods"] => [
"id" => 1,
"name" => "小熊",
"alias" => "littlebear",
"img_url" => "xxxx",
"desc" => "xxxxxx",
...
],
["goal_goods"] => [
"id" => 2,
"name" => "紅鑽",
"alias" => "reddiamond",
"img_url" => "xxxx",
"desc" => "xxxxxx",
...
],
["exchange_ratio"] => string(8) "1:985000"
["is_del"] => int(0)
["order"] => int(4)
},
[1] => array(6) {
...
},
...
如何用一條 SQL 語句查詢出這個結果?
想了半天沒找到SQL,求大神幫忙
我已經在 PHP 模型關系中解決了這種情況,謝謝!
public function getExchangeGoodsList() {
$gameGoodsConfigModel = new GameGoodsConfigModel();
$config = $gameGoodsConfigModel::all();
$goodsExchangeRuleList = [];
foreach ($config as $key => $obj) {
$itemArr = module_to_array($obj);
$itemArr['pay_goods'] = module_to_array($obj->goods);
$itemArr['goal_goods'] = module_to_array($obj->goalGoods);
array_push($goodsExchangeRuleList, $itemArr);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.