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

initial fetch() does not pull related objects #552

Open
visigoth opened this issue Nov 8, 2015 · 2 comments
Open

initial fetch() does not pull related objects #552

visigoth opened this issue Nov 8, 2015 · 2 comments
Labels

Comments

@visigoth
Copy link

visigoth commented Nov 8, 2015

i've got a model that i need to fetch from a known URL from the server. the model has a HasMany relation within it. on creation, i've got an identifier and i then invoke fetch() to grab it from the server. i would have expected backbone-relational to grab the relationship for me, but per https://github.com/PaulUithol/Backbone-relational/blob/master/backbone-relational.js#L1235, the override for trigger doesn't react to the sync event, which doesn't make sense to me: if the parent model has been fetched from the server, the relations should get fetched as well. am i missing something? i've got an override for Backbone.sync, but looking at the code for backbone-relational, it doesn't look like it would interfere.

let User = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'books',
relatedModel: Book,
includeInJSON: Backbone.Model.prototype.idAttribute,
collectionType: Books,
}]
});

let user = new User({id: 4});
user.fetch().then(() => { console.log(user.books); }); // should be an array of identifiers?

@mr-feek
Copy link

mr-feek commented Jun 7, 2016

Isn't this what the autoFetch key is for? It is defaulted to false, so toggling that to true should do what you are looking for (though I haven't tested).

@Abdillah
Copy link

Abdillah commented Jan 14, 2017

I tried to set the autoFetch: true, but it doesn't fetch it's relation model. After look on getAsync source code and test it out, seems the problem is, it stops after knowing the idsToFetch is empty. What other options should I supply?

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

4 participants