Backbone - Relational Nested Broken with KeySources
by jeffutter
HTML
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<script src="https://raw.github.com/gist/1506758/091d7f3680489ecb8b511e196edcfc2e52dd05c6/backbone-localstorage.js"></script>
<script src="https://raw.github.com/PaulUithol/Backbone-relational/master/backbone-relational.js"></script>
<html>
<head>
</head>
<body>
</body>
</html>
JavaScript
modelA = Backbone.RelationalModel.extend({
defaults: {
name: "modelA",
},
relations: [
{
type: Backbone.HasMany,
key: 'model_bs',
keySource: 'model_b_ids',
relatedModel: 'modelB',
collectionType: 'modelBs',
reverseRelation: {
key: 'model_a',
keySource: 'model_a_id',
includeInJSON: 'id'
}}
]
});
modelB = Backbone.RelationalModel.extend({
defaults: {
name: "modelB",
},
relations: [
{
type: Backbone.HasMany,
key: 'model_cs',
keySource: 'model_C_ids',
relatedModel: 'modelC',
collectionType: 'modelCs',
reverseRelation: {
key: 'model_b',
keySource: 'model_b_id',
includeInJSON: 'id'
}}
]
});
modelC = Backbone.RelationalModel.extend({
defaults: {
name: "modelC",
},
});
modelAs = Backbone.Collection.extend({
model: modelA,
localStorage: new Store("modelAs")
});
modelBs = Backbone.Collection.extend({
model: modelB,
localStorage: new Store("modelBs")
});
modelCs = Backbone.Collection.extend({
model: modelC,
localStorage: new Store("modelCs")
});
preLoadAs = [
{
id: 1,
name: 'Aone',
model_b_ids: [1, 2, 3]},
{
id: 2,
name: 'Atwo'},
{
id: 3,
name: 'Athree'},
]
preLoadBs = [
{
id: 1,
name: 'Bone',
model_c_ids: [1, 2, 3],
model_a_id: 1},
{
id: 2,
name: 'Btwo',
model_a_id: 1},
{
id: 3,
name: 'Bthree',
model_a_id: 1},
]
preLoadCs = [
{
id: 1,
name: 'Cone',
model_c_id: 1},
{
id: 2,
name: 'Ctwo',
model_c_id: 1},
{
id: 3,
name: 'Cthree',
model_c_id: 1},
]
loaderA = new modelAs();
loaderA.reset(preLoadAs);
loaderB = new modelBs();
loaderB.reset(preLoadBs);
loaderC = new modelCs();
loaderC.reset(preLoadCs);
testAs = new modelAs();
testAs.reset(preLoadAs);
testA =...