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

[CLEANUP BUGFIX] fix model and factory lookup #5446

Merged
merged 1 commit into from Apr 23, 2018

Conversation

runspired
Copy link
Contributor

@runspired runspired commented Apr 22, 2018

Resolves #4711
Resolves an issue with createRecord failing when being called for a non-existent model
Fixes an issue found with toString implementation in #5117

Example Fail case prior to this PR:

let person = run(() => store.push({
    data: {
      type: 'person',
      id: '1'
    }
}));

person.constructor.modelName; // will be unset

Previously, we had overly complicated the process of looking up a model with a mixture of public and private and public-looking but private methods. This complexity resulted in there being multiple code-paths by which a ModelClass could be looked up without a modelName or in which no factory for the ModelClass would be found but we would still attempt to create an instance from a missing factory.

Much of this complexity stemmed from the desire to check whether a ModelClass existed. I have strengthened our private _hasModelFor implementation, and trimmed us down to a single public modelFor hook and a single private _modelFactoryFor hook to eliminate confusion and prevent these sorts of errors from occurring.

Deprecates

  • _modelForMixin
  • _modelFor
  • modelFactoryFor

@runspired
Copy link
Contributor Author

cc @samselikoff @DingoEatingFuzz

@runspired runspired changed the title [FEAT BUGFIX] fix model and factory lookup [CLEANUP BUGFIX] fix model and factory lookup Apr 22, 2018
@runspired
Copy link
Contributor Author

runspired commented Apr 22, 2018

cc @Exelord for ember-custom-actions

This: https://github.com/Exelord/ember-custom-actions/blob/9c3f89723bb54a51a6bf480b866e8b458bf7ba54/addon/serializers/rest.js#L20

Will become this: store._hasModelFor(modelName).

This is the only usage found in the wild by ember-observer code-search for the now deprecated version of modelFactoryFor (besides ember-m3 which I've opened an issue for).

Happily no addons use _modelFor or _modelForMixin

@runspired
Copy link
Contributor Author

@Exelord I also meant to tell you that _hasModelFor is backwards compatible and is what should already have been in use there, it's safe to preemptively refactor to that now :)

@Exelord
Copy link

Exelord commented Apr 23, 2018

Ok! Thanks a lot Chris! I already migrated to it in the local branch. I will update the package soon :)

Copy link
Member

@bmac bmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great work @runspired.

@runspired runspired merged commit 40f6c62 into emberjs:master Apr 23, 2018
@runspired runspired deleted the fix-factory-for branch April 23, 2018 20:14
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

Successfully merging this pull request may close these issues.

None yet

3 participants