【发布时间】:2020-04-26 13:19:26
【问题描述】:
我遇到了一个名为“字段列表中的列 'id' 不明确”的错误问题。
我尝试通过在列上使用别名来修复它,但我没有修复它。查询如下所示:
SELECT `id` AS `pf_id`,
`id_feature` AS `pf_if`,
`id_feature_value` AS `pf_ifv`,
`product_features`.`id_product`
FROM `features`
INNER JOIN `product_features`
ON `product_features`.`id_feature` =
`features`.`pf_id`
WHERE `product_features`.`id_product` IN (
33003, 33004, 33011, 33012,
33013, 33015, 33016, 33017,
33018, 33019, 33020, 33021,
33022, 33023, 33024, 33025,
33026, 33029, 33030, 33032 )
AND `id_feature` = 5
Id 仅用于选择和内部连接。它正在调用 product_features 表和 features 表。只有这段代码不起作用 - 产品上的任何其他关系都可以正常工作。以下是有关表结构和关系的附加信息:
$products = Product::select('id', 'id as DT_RowId', 'id_manufacturer', 'sku', 'price_retail', 'active')
->with([
'manufacturer' => function ($m) {
$m->with(['defaultTranslation' => function ($query) {
$query->select('id', 'id_manufacturer', 'name');
}]);
},
'defaultTranslation' => function ($dt) {
$dt->select('id', 'id_product', 'name');
},
'features' => function ($qf) {
$qf->select('id as pf_id', 'id_feature as pf_if', 'id_feature_value as pf_ifv');
$qf->where('id_feature', 5);
},
]);
$result = $products->orderBy('id', 'DESC')->paginate($itemNumber, ['*'], 'page', $page);
product_features 结构:
特点:
特征关系(来自模型的函数)
public function features()
{
return $this->hasManyThrough('App\SupremeShop\Models\Feature',
'App\SupremeShop\Models\ProductFeature',
'id_product',
'id',
'id',
'id_feature');
}
感谢您的帮助!
【问题讨论】:
-
请您复制并粘贴您的代码而不是添加它的屏幕截图。