Hi,
I'm trying to get a query builder that is already joining a relation to eager load them (Unfortunately I need a "Query Builder" to be later used and passed to another package).
I'd suspect the following code to already join the two tables, but it doesn't:
> Employee::query()->with('company')->toSql();
= "select * from `employees`"
The parent model does have the relation defined:
public function company()
{
return $this->belongsTo(Company::class);
}
Am I misusing the query builder functionality or do I miss something? I'd expect something like:
> Employee::query()->with('company')->toSql();
= "select * from `employees` left join `companies` on `employees`.`company_id` = `companies`.`id`"
Thanks a lot