Zatvobor / ember-couchdb-kit

An Ember.js adapter for Apache CouchDB
MIT License
43 stars 13 forks source link

Need to load the async hasMany before calling save or else it gets saved as an empty array #78

Closed simonexmachina closed 11 years ago

simonexmachina commented 11 years ago

If I have the following models:

App.Budget = DS.Model.extend accounts: DS.hasMany 'account', async: true
App.Account = DS.Model.extend budget: DS.belongsTo 'budget'

And the following document:

{
  _id: "a8e57e4af8510a7b6f63c40d37017dc8",
  accounts: [
    "5a3dfebdb35a829cd009b77b4f001567",
    "5a3dfebdb35a829cd009b77b4f0019fb"
  ]
}

If I call budget.save() before loading the accounts (i.e. budget.get('accounts').then -> budget.save()) then the budget get saved with accounts: [].

budget = @store.find('budget', 'a8e57e4af8510a7b6f63c40d37017dc8').then ->
  budget.save() # budget gets saved with accounts: []

Workaround is:

budget = @store.find('budget', 'a8e57e4af8510a7b6f63c40d37017dc8').then (budget)->
  budget.get('accounts')
.then ->
  budget.save() # budget gets saved with accounts ids