I have pinpointed some behavior I'd like to see if anyone can explain.
I made a jsfiddle here http://jsfiddle.net/iceking1624/PpWec/17/. To test behavior, open web console and simply type something in the textfield next to 'Add Question' button and then hit the button('Add Question').
Here are the DS.Model
schemas:
App.Session = DS.Model.extend({
"questions" : DS.hasMany('App.Question') ,
"firstQuestion" : DS.belongsTo('App.Question')
});
App.Question = DS.Model.extend({
"session" : DS.belongsTo('App.Session'),
"choices" : DS.hasMany('App.Choice'),
"text" : DS.attr('string')
});
App.Choice = DS.Model.extend({
"session" : DS.belongsTo('App.Session'),
"question" : DS.belongsTo('App.Question'),
"text" : DS.attr('string')
});
When I do the following inside SessionController
then call the addQuestion
function:
App.SessionController = Ember.ObjectController.extend({
addQuestion: function() {
var sessionModel = this.get('model');
var question = App.Question.createRecord({
"session" : sessionModel
});
this.get('questions').pushObject(question)
}
});
I get the following 'error' but it functions as expected nonetheless:
Error: assertion failed: You defined the 'session' relationship on App.Question, but multiple possible inverse relationships of type App.Question were found on App.Session.
Now I figured out it's because inside App.Session
I have two fields that reference App.Question
:
"questions" : DS.hasMany('App.Question') ,
"firstQuestion" : DS.belongsTo('App.Question')
but I'm wondering why Ember cares that I have multiple App.Question
relationships?? And especially why it would throw an error, yet work perfectly. Is this a bug perhaps?
Is there a way I can make Ember happy and not throw an error??? I really need that firstQuestion
field in my App.Session model.
Open the console and look at my jsfiddle. It's a perfect example of my issue. Then try commenting out firstQuestion
in the App.Session = DS.Model
and watch how the error magically disappears