getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

Must be attached to a session. #142

Open dev-inigmas opened 10 years ago

dev-inigmas commented 10 years ago

I just got an error that seems pretty weird to me.

Uncaught Error: Assertion Failed: Must be attached to a session. deps.js:23517
Ember.assert deps.js:23517
require.define.Ep.LazyModel.Ep.ModelPromise.extend.load deps.js:74141

Not really sure what seems to be going on. Basically, I'm trying to set an object to the primary model's "belongsTo" attribute. And then flush the session. I've done some print outs that the model I'm setting has a Session. (Should be the same session as the parent model). But I'm consistently getting this error.

Any ideas?

dev-inigmas commented 10 years ago

Okay, so it seems like "Bindings" are interfering the session's ability to flush.

I have some business logic in some of my models. In one case, I tried making a property of a related model easier to access by creating a binding to it. For instance:

App.Foo = Ep.Model.extend
  name: Ep.attr 'string'
  bar:     Ep.belongsTo 'bar'
  bvBinding: 'bar.value'

App.Bar = Ep.Model.extend
  value: Ep.attr 'number'
  foos:   Ep.hasMany 'foo', inverse: 'bar'

Replacing with binding with a computed property seems to be a good workaround for now.

ghempton commented 10 years ago

Ah I could see this happening in some binding cases. I am working on a refactor that could fix some of these issues.

On Wed, Jul 16, 2014 at 1:02 AM, David Patrick notifications@github.com wrote:

Okay, so it seems like "Bindings" are interfering the session's ability to flush.

I have some business logic in some of my models. In one case, I tried making a property of a related model easier to access by creating a binding to it. For instance:

App.Foo = Ep.Model.extend name: Ep.attr 'string' bar: Ep.belongsTo 'bar' bvBinding: 'bar.value'

App.Bar = Ep.Model.extend value: Ep.attr 'number' foos: Ep.hasMany 'foo', inverse: 'bar'

Replacing with binding with a computed property seems to be a good workaround for now.

— Reply to this email directly or view it on GitHub https://github.com/getoutreach/epf/issues/142#issuecomment-49134913.

Gordon L. Hempton http://codebrief.com 360.460.8098

ghempton commented 10 years ago

Also, fwiw, I would recommend using computed property aliases rather than bindings (which are eagerly evaluated). In your case it would be bv: Ember.computed.alias('bar.value')