I slightly modified an example from the docs, to create a reverse relation in HasOne-HasOne scenario (a Zoo contains an Animal, and the reverse relation on the Animal should point back to the Zoo). The problem is the reverse relation doesn't get initialized. The following code results in "undefined", I expect it to return "artis" though. Am I missing something? How to create a reverse relation in HasOne-HasOne?
Zoo = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasOne,
key: 'animal',
relatedModel: 'Animal',
reverseRelation: {
key: 'livesIn',
type: Backbone.HasOne
}
}]
});
Animal = Backbone.RelationalModel.extend({});
var artis = new Zoo({ animal: {} });
console.log(artis.get('animal').livesIn);