DS.Model is asked to materialize when belongsTo bindings are being connected #549

mbixby opened this Issue Dec 25, 2012 · 1 comment


None yet

2 participants

mbixby commented Dec 25, 2012

Say I have these models and a binding:

App.Order = DS.Model.extend
  tableBinding: 'device.table'
  device: DS.belongsTo App.Device

App.Device = DS.Model.extend
  table: # some property

When an Order object is being created, its bindings will get resolved first and then the Order.init() function will be executed.

The problem is that when the Order wants to connect its tableBinding, it needs to access the device (DS.belongsTo computed property), which in turn has to materialize the Order record, which in turn needs to access its stateManager.

It can't do this for two reasons: 1. the stateManager is not yet initialized (since the Order's init method has not run yet) and 2. records cannot be materialized in 'empty' state.

Is this ok?

This is what I expected "tableBinding: 'device.table'" to do:

table: ((key, value) ->
    if arguments.length is 1
      @get 'device.table'
      @set 'device', value

Sidenote: Why does Ember prefer init methods to memoized properties?

  stateManager: (->
    manager = DS.StateManager.create { record: this }
    manager.goToState 'empty'
wagenet commented Aug 10, 2013

A few points:

  1. StateManager is gone now.
  2. init was preferred to memoized properties because CPs carry some overhead. However, if you now have a readOnly CP with no dependencies, Ember will just cache the value on first access and use that in the future instead of calling the function, so this shouldn't be an issue either.

Due to these, I suspect this is no longer an issue.

@wagenet wagenet closed this Aug 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment