Отсюда: https://laravel -news.com / eloquent-eager-loading
Запуск этой строки: App\Post::with('author.profile')->get();
приводит к выполнению 3 запросов:
[2017-08-04 07:27:27] local.INFO: select * from `posts`
[2017-08-04 07:27:27] local.INFO: select * from `authors` where `authors`.`id` in (?, ?, ?, ?, ?) [1,2,3,4,5]
[2017-08-04 07:27:27] local.INFO: select * from `profiles` where `profiles`.`author_id` in (?, ?, ?, ?, ?) [1,2,3,4,5]
Как получилось?Есть ли чистый способ сделать это в одном запросе?
Я ожидаю, что результирующий запрос будет выглядеть примерно так:
SELECT *
FROM posts, authors, profiles
WHERE posts.author_id = author.id
AND author.profile_id = profiles.id