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

Issue with new include feature when basic request already sent off #4390

Closed
adam-knights opened this issue May 20, 2016 · 2 comments
Closed
Labels
🏷️ feat This PR introduces a new feature

Comments

@adam-knights
Copy link
Contributor

adam-knights commented May 20, 2016

I spent all morning trying to work out why this line of code, in an after model hook, kept hitting /members/123 rather than members/123?include=orders

let memberPromise = this.store.findRecord('member', 'model.get('member.id')', { include: ['orders'] });

I've reproduced similar in a twiddle:

https://ember-twiddle.com/d9a58e2070bbdefeb2e9954767830768?fileTreeShown=false&numColumns=2&openFiles=routes.application.js%2Ctemplates.application.hbs

Essentially because you use model.get('pet.id') that first fires off a request to pets/30, I imagine the findRecord then sees it is already waiting on a response for a pet with id 30 - and so doesnt fire a new request to the url I wanted - pets/30/include=toys

@HeroicEric any thoughts?

I feel like what I had done was slightly wrong, but I'd have rather seen a warning/error as it was very hard to spot - or should ember data make a second request with the includes, after the original basic request comes back?

Question boils down to - if findRecord is already waiting on a request with NO includes, but then a new request comes in WITH includes - what should it do?


FYI I sorted my code, which was to do

this.store.findRecord('member', model.belongsTo('member').id(), { include: ['orders'] });

Thanks to the new ds refs behavior

@wecc
Copy link
Contributor

wecc commented Oct 29, 2016

@adam-knights sorry for the late response, your work-around looks good. References are the way to go to access information about relationships without triggering network requests.

I'm inclined to close this in favor of Support self links for relationships (reloading, saving, deleting) tracked in #2905. I would like this to allow for loading/reloading relationships with provided include, somehow.

Highly pseudo: post.belongsTo('author').load({ include: 'company' }). This needs to be discussed in more details though and go through the RFC process.

@adam-knights
Copy link
Contributor Author

@wecc sounds good, feel free to close and do through #2905 .

@wecc wecc closed this as completed Oct 31, 2016
@runspired runspired added 🏷️ feat This PR introduces a new feature and removed Improvement labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ feat This PR introduces a new feature
Projects
None yet
Development

No branches or pull requests

4 participants