首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SQLSTATE[42S22]:在Laravel中找不到列

SQLSTATE[42S22]:在Laravel中找不到列
EN

Stack Overflow用户
提问于 2020-04-14 03:49:14
回答 2查看 107关注 0票数 1

您好,以下是我的查询,但在运行时出现错误:

代码语言:javascript
运行
复制
$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');”这一行中,系统抛出的错误如下:

"message":"SQLSTATE42S22:未找到列: 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 null)",

EN

回答 2

Stack Overflow用户

发布于 2020-04-14 05:30:15

我猜combinationsprices引用了不同的表,并且您在combinations中使用了price.active。试着用这个

代码语言:javascript
运行
复制
$out_let_product = OutLet::where('id', Redis::get('out_let_id') )->with(
    ['products' => function($query){
        $query->with(['combinations' => function($query){
            $query->select('combinations.*', 'prices.*')
                  ->join('prices', function($join) {
                      $join->on('prices.id' '=', 'combination.id') // or your join logic
                           ->where('prices.active', '=', 1)                    
                  })->where(// where clause for combination);
    }])->get();
票数 0
EN

Stack Overflow用户

发布于 2020-04-16 10:10:57

哦,是的,我有我的解决方案:

代码语言:javascript
运行
复制
$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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61195592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档