I am evaluating the Backbone-Relational plugin for modeling a tree. I have the following sample code
var SurveyTreeNode = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'questions',
relatedModel: 'SurveyTreeNode'
}]
});
var survey = {
id: 1,
questions: [
{
id: 2,
text: 'What is your name?'
},
{
id: 3,
text: 'What hours do you work?',
questions: [
{
id: 3,
text: 'On Monday?'
},
{
id: 4,
text: 'On Tuesday?'
}
]
}
]
};
var questionTree = new SurveyTreeNode(survey);
which yields (in Google Chrome console):
no model, key or relatedModel (function (){ parent.apply(this, arguments); }, "questions", undefined)
I've loaded this code into a jsfiddle, as the error doesn't display exactly as above (shows a child element that can be expanded): http://jsfiddle.net/hoffmanc/XsDQu/