You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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).
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?
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?
The text was updated successfully, but these errors were encountered: