laravel - SQLSTATE[42S22]:在 Laravel 中找不到列
问题描述
您好以下是我的查询,但运行时出现错误:
$out_let_product = OutLet::where('id', Redis::get('out_let_id') )->with(
['products' => function($query){
$query->with(['prices', 'combinations' => function($query){
$query->where('prices.active', '=', '1');
}]);
}])->get();
在上面的代码中,“价格”和“组合”=产品模型中的功能。它运行良好,但问题是当我在其中包含“ $query->where('prices.active', '=', '1'); ”这一行时,系统引发如下错误:
“消息”:“SQLSTATE [42S22]:未找到列:1054 'where 子句'中的未知列'prices.active'(SQL:select * from product_combinations
where product_combinations
. product_id
in (1, 2, 3) and prices
. active
= 1 and product_combinations
. deleted_at
is无效的)”,
解决方案
哦,是的,我得到了我的解决方案:
$out_let_product = OutLet::where('id', Redis::get('out_let_id') )->with(
['products' => function($query){
$query->with(['prices' => function($query){
$query->where('product_prices.active', '=', '1'); //product_prices is DB: Table name
}]);
$query->with(['combinations' => function($query){
query->where('product_combinations.id', '1'); //product_combinations is DB: Table name
}]);
}])->get();
推荐阅读
- selenium - 在我的自动化项目的测试类中调用驱动程序时,我遇到了空指针问题。我该如何解决这个问题?
- php - 解析具有相同名称的多个标头
- bash - 使用 echo 逐行打印一个数字序列
- django - 如何在 django 中预定义关联的模型外键
- sql - 检查特定条件下的重复值
- javascript - 如何在 NodeJS 后端应用程序上允许 CORS
- facebook - 页面评级需要两因素身份验证
- visual-studio-code - vscode中的强制面板(终端)默认大小
- apache-spark - 使用 PySpark 从字符串中获取倒数第二个单词
- python - Convert string byte to byte like b'\x00\x01\x02'