【发布时间】:2020-04-08 18:29:32
【问题描述】:
当我这样做时
$category = NewsCategory::whereSlug($slug)->with('news.category:id,title,slug')->firstOrFail();
然后我有以下查询
select * from `news_categories` where `slug` = 'novinki' limit 1
select * from `news_posts` where `news_posts`.`category_id` in (2) and `news_posts`.`deleted_at` is null
select `id`, `title`, `slug` from `news_categories` where `news_categories`.`id` in (2)
但我也想在第一个新闻关系上加载特定列,如果我这样做会出错
$category = NewsCategory::whereSlug($slug)->with('news:id,title,image.category:id,title,slug')->firstOrFail();
获取此查询的正确方法是什么?
select * from `news_categories` where `slug` = 'novinki' limit 1
select `id`, `title`, `image` from `news_posts` where `news_posts`.`category_id` in (2) and `news_posts`.`deleted_at` is null
select `id`, `title`, `slug` from `news_categories` where `news_categories`.`id` in (2)```
【问题讨论】:
标签: laravel eloquent eager-loading