I've got backbone-relational working fairly well so far. I have relationships and reverse relationships well established (see below). When I initially call .fetch()
on my Country
model instance, the nominees
array is parsed out into nominee
models perfectly.
When I call .fetch()
again later, however, these related models do not update, even though the nominee
data has changed (e.g. the vote count has incremented). Essentially it seems that Backbone's .set()
method understands relationships initially but not subsequently.
Country Model
var Country = Backbone.RelationalModel.extend({
baseUrl : config.service.url + '/country',
url : function () {
return this.baseUrl;
},
relations : [
{
type : Backbone.HasMany,
key : 'nominees',
relatedModel : Nominee,
collectionType : Nominee_Collection,
reverseRelation : {
key : 'country',
includeInJSON : false
}
}
]
});
JSON Response on country.fetch()
{
"entrant_count" : 1234,
"vote_count" : 1234,
"nominees" : [
{
"id" : 3,
"name" : "John Doe",
"vote_count" : 1,
"user_can_vote" : true
},
{
"id" : 4,
"name" : "Marty McFly",
"vote_count" : 2,
"user_can_vote" : true
}
]
}
Any help would be greatly appreciated, as always.