Data: Unable to set defaultValue on belongsTo and hasMany

Created on 7 May 2014  路  7Comments  路  Source: emberjs/data

In my case, I would like to set the defaultValue of a belongsTo relationship to the current user, but can think of other use cases for this.

Most helpful comment

+1 on getting a more detailed explanation from @bmac please.

All 7 comments

Would like this functionality also.

aye.

+1

Closing this issue. Now that Ember has Services they are a better place to encapsulating the logic around assigning a "default" relationship on a model.

@bmac Could u explain a little more detailed how to use services this way, please?

+1 on getting a more detailed explanation from @bmac please.

I'd say @bmac is probably suggesting something along these lines:

// app/services/foo.js
export default Ember.Service.extend({
  barFor(foo) {
    return foo.get('bar') || foo.set('bar', defaultValue())
  }
})

I've decided to put this into the adapter, and access it using store.adapterFor('foo').barFor(foo)

Was this page helpful?
0 / 5 - 0 ratings