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

Storefront query with reference objects #146

Open
ryanto opened this issue Jul 30, 2019 · 2 comments
Open

Storefront query with reference objects #146

ryanto opened this issue Jul 30, 2019 · 2 comments
Labels

Comments

@ryanto
Copy link
Member

ryanto commented Jul 30, 2019

You can pass objects by reference to ember data queries, so you can so something like...

this.store.loadRecords('post', { filter: { slugs: ['post-1', 'post-2'] } })

and the backend is going to get an array of slugs that it can use to filter

there's an issue where if storefront gets a mutable array, that array can be mutated, and internally change so the query ends up not reflecting the data

this.store.loadRecords('post', { filter: { slugs: this.queryParams.slugs } })

now as slugs get added and removed from some controller action, that same array is used in the query.


The fix here is to copy/clone reference objects that are passed to storefront.

@ryanto ryanto added the Bug label Jul 30, 2019
@charlesfries
Copy link

Bump

@ryanto
Copy link
Member Author

ryanto commented Jun 25, 2021

Hey @charlesfries is this giving you trouble?

My recommendation would be to copy anything so you don't have pointers to stale objects.

For example, the original issue could be solved by using:

this.store.loadRecords('post', { filter: { slugs: [...this.queryParams.slugs] } })

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

No branches or pull requests

2 participants