2019-03-06 15:34:53 2145次浏览 4条回答 0 悬赏 10 金钱
public function actionDetail()
{
    Yii::$app->response->format = Response::FORMAT_JSON;
    $request = Yii::$app->request;

    $product = ProductModel::find()
        ->where([
            'product.main_id' => $request->get('id'),
        ])
        ->with(['standard' => function ($query) {
            $query->select(['name', 'main_id']);
        }])
        ->asArray()
        ->all();

    return $this->searchSuccess($product);
}

请问一下这段代码里面的 with 是什么意思呢?谢谢大佬

最佳答案

  • 刘师傅 发布于 2019-03-07 09:35 举报

    其实是一种关联查询的实现方式,就是join而已嘛。只不过关联关系on的定义在模型里而不是在sql这里。
    从你的代码看,ProductModel里肯定有一个getStandard()方法定义了关联关系。

    觉得很赞
您需要登录后才可以回答。登录 | 立即注册
PHP学院的中学生
副总裁

PHP学院的中学生

注册时间:2018-10-23
最后登录:2023-07-25
在线时长:167小时55分
  • 粉丝29
  • 金钱4725
  • 威望30
  • 积分6695

热门问题