Изучая Laravel 5.7 на Laracasts.com, он показал, как получить 1:N
записей отношений из базы данных с объектами модели Eloquent следующим образом.
// One SQL query is being executed here.
$project = Project::first();
// Another SQL query must be executed here to be abled to count the tasks. Right?
if ($project->tasks->count()) {
// Is another SQL query being executed here to fetch the task's records related to the project?
foreach ($project->tasks as $task) {
echo $task->name;
}
}
Сколько запросов SQL было выполнено с помощью вышеуказанного подхода? Я не уверен, что 2 или 3 SQL-запроса выполняются.