Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_internalModel is undefined on 'init' of a record. #3255

Closed
ghost opened this issue Jun 8, 2015 · 7 comments
Closed

_internalModel is undefined on 'init' of a record. #3255

ghost opened this issue Jun 8, 2015 · 7 comments

Comments

@ghost
Copy link

ghost commented Jun 8, 2015

Testcase: http://jsbin.com/cegapapigo/2/edit?html,css,js,output

DS.Model.extend({
  foo: DS.attr('string'),
  initFoo: Ember.on('init', function() {
    this.get('foo');
  })
})._create();
@sly7-7
Copy link
Contributor

sly7-7 commented Jun 8, 2015

It's because the model receive it's internalModel after its creation (and obviously after the init method): https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/internal-model.js#L117

setting this internalModel inside the _createCall should do the trick, but I'm almost sure there was a good reason not to do it. (even if the tests pass)

cc/ @wecc @igorT

@bmac
Copy link
Member

bmac commented Jun 8, 2015

@martndemus what is your use case for creating records using _create instead of using the store's apis for creating a record?

@ghost
Copy link
Author

ghost commented Jun 8, 2015

@bmac It's just as simple demonstration, I don't actually use _create. _create is simply used by all the public manners of initializing a record.

(So my case is that createRecord and down the line push uses it.)

@sly7-7
Copy link
Contributor

sly7-7 commented Jun 8, 2015

@bmac It seems fair for me as a user to be able to do some things on('init'), like we may do in views or controllers.

@bmac
Copy link
Member

bmac commented Jun 8, 2015

Seems fair. @igorT how do you feel about the idea of passing _internalModel in as one of the properties on the object passed into to _create(...)?

@igorT
Copy link
Member

igorT commented Jun 8, 2015

We should have a separate hook as to not to have to guarantee ordering, but @bmac that solution seems ok for now

@bmac
Copy link
Member

bmac commented Jun 9, 2015

@martndemus We have release Ember Data v1.0.0-beta19.1 with a fix for this issue: http://emberjs.com/blog/2015/06/09/ember-data-1-0-beta-19-1-released.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants