0
votes

Having strange issue with saving hasMany relationships from a primary model, looking for advice:

My setup: Ember : 1.11.0-beta.1+canary.48e11592 Ember Data : 1.0.0-beta.14.1 EmberFire : 1.3.2 jQuery : 1.11.2

Relationship (pseudo): customer hasMany widgets widget belongsTo customer

addRelatedWidget: function() {
  var data = this.get('addWidget');
  var model = this.get('model');
  var widget = this.store.createRecord('widget', {
    name: data.name.trim(),
    _time: new Date().getTime(),
    customer: model,
  });
  widget.save().then(function(widget){
    model.save();
  });
  this.set('addWidget', {
    name: ''
  });
}

Symptoms: When I add a widget from the customer view and persist the save, as above, the Chrome browser I'm adding in correctly shows one instance of the newly saved widget. The data at FireBase is correctly showing the new widget and it's joined to the customer as expected. But, if I have any other browser windows open - doesn't matter if it's another chrome, incognito window, or safari - I get TWO versions of the widget displayed in the list of related widgets.

If I use Ember Developer Toolbar in Chrome to debug, I see two instances of the SAME OBJECT - same id, same ember model:

<ember-app@model:widget::ember1553:-JggK7ByZqaNhrJ4PJyq>
<ember-app@model:widget::ember1553:-JggK7ByZqaNhrJ4PJyq> 

And to look at the serialized models from the DS.model.tab tab in Ember toolbar:

Ember Inspector ($E):  Object {_time: 1422377911584, customer: "12", name: "Adding", id: "-JggK7ByZqaNhrJ4PJyq"}

Ember Inspector ($E):  Object {_time: 1422377911584, customer: "12", name: "Adding", id: "-JggK7ByZqaNhrJ4PJyq"}

They appear to be two exact duplicates of the exact same instance of the model.

So I haven't been able to debug this. Since its not the data at firebase and the working browser shows fine, I wonder if it's the new HTMLBars templating engine in 1.9 ... maybe it's even emberfire handling events incorrectly?

I doubt it's emberfire, since I imagine it wouldn't be possible to have two instances of a related model in the same array, because of the fact that related model data in firebase is stored by -primary-key: true ...

Can anyone guide me on where to start debugging this?

Thanks

1
Right now EmberFire supports Ember 1.9.1 and Ember Data beta.12 (you can see the latest versions EmberFire supports here: github.com/firebase/emberfire#downloading-emberfire). Could you try with those versions and see if you're getting the same issue? I'm guessing this will be fixed with ED beta.15.Sara
Yeah, you're right Sara, that did address it, it's a versioning issue. Thanks. However still not sure if its emberfire / compatibilities or the new HTMLBars as I have to disable HTMLBars in order to work with 1.9.1 ... OT: I know you mentioned before that your team was working on updating the emberfire adapter to support latest versions and include some of the new query methods - do you have an ETA on this by chance? It would be good to take advantage of them and HTMLBars compatible with 1.10+ and canary.Tremendus Apps
One of you two should post the correct answer so we can resolve this. It hurts my OCD to have unanswered Firebase questions : )Kato

1 Answers

0
votes

Per Kato: Sara posted that it is a version incompatibility and she is correct. EmberFire isn't ready for Ember > 1.9.1, but 1.9.1 works exactly as expected :)