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

Provide support for lazy-loading relations at access time #800

Open
ocratravis opened this issue May 18, 2023 · 0 comments
Open

Provide support for lazy-loading relations at access time #800

ocratravis opened this issue May 18, 2023 · 0 comments

Comments

@ocratravis
Copy link

ocratravis commented May 18, 2023

Is your feature request related to a problem? Please describe...

Suppose that I have a Company model, which has many Employee models.

Currently, I can't do this:

const company = Company.find(123)
console.log(company.employees) // outputs an empty array, even if company 123 does have employees

Instead, I have to make sure that the employees relation gets loaded as part of the initial query:

const company = Company.query().with(['employees']).whereId(123).first()
console.log(company.employees) // outputs the related employees, as expected

If the code which needs to display the employees is in a different part of the app than the code which initially loads the company, this behavior creates a tight coupling between the two parts of the app.

Describe the solution you'd like

When I try to access a relation that hasn't yet been loaded, I would like Vuex ORM to lazy-load the related model(s). This is consistent with other ORMs that I've used, such as Laravel Eloquent.

const company = Company.find(123)
console.log(company.employees) // Vuex ORM sees that this relation hasn't yet been loaded, and lazy-loads it from the store
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant