0

I read a lot of, still can't solve by myself. I've an Ember Route, with az EmberFire model.

App.NewRoute = Ember.Route.extend({
model: function() {
    return EmberFire.Object.create({
        ref: window.ref
    });
},
setupController: function(controller, model) {
    controller.set('model', model);
})

After that for example I've in the controller:

App.NewController = Ember.Controller.extend({
actions: {
    save: function() {
        this.get('model').set('questions', Ember.A([]));
        this.get('model').get('questions').pushObject(Ember.Object.create({title: 'foo'}));
        this.get('model').get('questions').get('lastObject').set('title', 'bar');

        this.get('model').set('title', 'foobar');
    }
}
});

When the save action called only the title change is made on fire base.

Can someone please explain how can I changed the array too?

1 Answers1

0

I would change your model from an EmberFire.Object.create to an EmberFire.Array.create. Instead of having an object with an array as a property. EmberFire is a simple wrapper that bridges ember objects to firebase objects. I don't think it works with nested arrays inside an object yet as I just started working with the library.

If you need a property identified to that array in an object, create a second object EmberFire.Object and add a property questions that references this EmberFire.Array firebase object instead.

So your save action would look more like this:

var array = this.get('model');  
array.pushObject(Ember.Object.create({title: 'foo'}));  
array.get('lastObject').set('title', 'bar');  
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
Drew P
  • 21
  • 3