Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for eager loading specific columns without requiring those columns #98

Open
samatcd opened this issue Oct 15, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@samatcd
Copy link

samatcd commented Oct 15, 2020

When eager loading specific columns on a related record, you can use a special syntax to define the columns per the Laravel docs:

$books = App\Models\Book::with('author:id,name')->get();

When using a standard Laravel relationship definition, you don't need to specify the key fields in this eager loading, but you do when using a composite relationship. E.g., let's say I have the following relationship:

$this->hasOne(Author::class, ['author_id', 'ghostwriter_id'], ['author_id', 'ghostwriter_id']);

In order for the eager loading to work properly, I need to specify the key fields in the eager loading (even though I don't need those values).

$books = App\Models\Book::with('author:id,name,author_id,ghostwriter_id')->get();

It would be nice if those could be automatically handled without having to include them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants