1
votes

I'm trying to change a belongsTo using the built in ember select view. However, when the select box changes only the belongs to attribute is updated, not the hasMany relationship. The following jsbin shows this behaviour http://jsbin.com/ewosiy/3/edit.

In this example a person hasMany events and an event belongsTo a person. If I change who the event belongsTo, the event is removed from the original person but never added to the new person.

I could roll my own select-box component but just wondered if the ember select really is not updating both ends of the relationship.

Thanks.

1
Your jsbin, updated to work with latest Ember: jsbin.com/axOhIBih/1denis.peplin

1 Answers

2
votes

in order to make it work, you need to use 'pushObject' in the relation of your 'person' object, you would need to do something like this:

change your select to this:

{{view Ember.Select
    contentBinding=controllers.application.model
    optionValuePath=content.id
    optionLabelPath=content.fullName
    selectionBinding=selectedPerson}}

and in your eventController add this:

selectedPersonChanged: function() {
  if(this.get('selectedPerson')) {
    this.get('selectedPerson.events').pushObject(this.get('content'));
  }
}.observes('selectedPerson')