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

[BUGFIX beta] Ensure container can still be provided to .create. #12731

Merged
merged 1 commit into from
Dec 19, 2015

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Dec 19, 2015

In Ember versions until 2.3.0 it was common to provide a container property (if needed) when creating instances of a factory manually. This might look like:

let Foo = container.lookupFactory('model:foo');
let instance = Foo.create({
  container
});

Many addons did this (examples include ember-cp-validations and ember-data).

Our initial implementation of the deprecated container property on extendable factories used Object.defineProperty to ensure calling instance.container returned the correct value. Unfortunately, we only defined a getter which means calling Foo.create({ container }); triggers the following error:

Cannot set property container of [object Object] which has only a getter

This change adds a setter (with an appropriate deprecation) to prevent triggering an error.

Without this change, using Ember Data 2.2.0 with Ember 2.3.0 fails.


/cc @dgeb

In Ember versions until 2.3.0 it was common to provide a `container`
property (if needed) when creating instances of a factory manually. This
might look like:

```
let Foo = container.lookupFactory('model:foo');
let instance = Foo.create({
  container
});
```

Many addons did this (examples include ember-cp-validations and ember-data).

Our initial implementation of the deprecated `container` property on extendable
factories used `Object.defineProperty` to ensure calling
`instance.container` returned the correct value. Unfortunately, we only
defined a getter which means calling `Foo.create({ container });`
triggers the following error:

```
Cannot set property container of [object Object] which has only a getter
```

This change adds a setter (with an appropriate deprecation) to prevent
triggering an error.
@stefanpenner
Copy link
Member

Does this need to be in release? It looks similar to something I swear I saw in release. (But it's possible it was something else)

@rwjblue
Copy link
Member Author

rwjblue commented Dec 19, 2015

No, ember-inject-owner feature is only in beta. It is possible that there is another related scenario from 2.1's public introduction of ember-container-reform feature. I can look into that later tonight (will make a separate PR if I find additional getter only scenarios like this).

@dgeb
Copy link
Member

dgeb commented Dec 19, 2015

Great catch @rwjblue. LGTM 👍

rwjblue added a commit that referenced this pull request Dec 19, 2015
[BUGFIX beta] Ensure `container` can still be provided to `.create`.
@rwjblue rwjblue merged commit 01b1107 into emberjs:master Dec 19, 2015
@rwjblue rwjblue deleted the fix-setting-container-on-create branch December 19, 2015 21:40
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.

3 participants