Zatvobor/ember-couchdb-kit

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

Closed this issue · 0 comments

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