I'm working with Ember with Rails Backend
Ember.VERSION : 1.0.0-rc.3 ember.js:349
Handlebars.VERSION : 1.0.0-rc.3 ember.js:349
jQuery.VERSION : 1.9.1
I have three models
App.SocialNetwork = DS.Model.extend({
name: DS.attr('string'),
actors: DS.hasMany('App.Actor'),
relations: DS.hasMany('App.Relation'),
});
App.Actor = DS.Model.extend({
name: DS.attr('string'),
x: DS.attr('number'),
y: DS.attr('number'),
social_network: DS.belongsTo('App.SocialNetwork'),
relations: DS.hasMany('App.Relation'),
isSelected: function () {
return false;
}.property(),
});
App.Relation = DS.Model.extend({
name: DS.attr('string'),
actors: DS.hasMany('App.Actor'),
social_network: DS.belongsTo('App.SocialNetwork'),
});
And Inside my RelationsController I want to create a new instance of Relation
I tried to do it like this
App.RelationsController = Ember.ArrayController.extend({
currentRelation: null,
add: function () {
// get the selected actors
var actors = this.get('socialNetwork.actors').toArray().filter(function (element) {
return element.get("isSelected") == true;
});
// create the new relation with those actors
var newRelation = App.Relation.createRecord({
actors: actors,
name: "New Relation",
});
this.set('currentRelation', newRelation);
this.get('content').pushObject(newRelation);
this.get('store').commit();
},
});
But the relation is not being stored, and I debug the new record created and it doesn't have any actors or social network associations.
What I'm doing wrong or not doing here?
Thanks in advance for your help
PS: by the way, the socialNetwork and actors load correctly