emberjs/data — pull request #1952 by mixonic (2014-05-17 16:55:49+00:00)
Title: Do not cache model factories on meta, or on other model CPs

**tl;dr: Keep model factory references from leaking between multiple containers (i.e. multiple tests). Without this, the FixtureAdapter is broken in ember-cli, and a lot of other things only really work by coincidence.**

Relationships are hard. Ember-Data has been storing data about a relationship on the meta value for that CP. CPs hang around though, and as a result that data on the meta becomes a cache. For some details about a relationship, this is fine.

If `User` has many `Posts`, and you use `User` via a container, it would cache a reference to the `Post` factory. But if you then destroy that container, the reference to `Post` still exists in the CP meta. Furthermore, if you create a new container and use `User` and `Post` via that new container, the cache factory value for `Post` will be that of the old container and not the new container.

This only is a problem if you expect to have `Post` be a different factory in each container. In ember-cli, `MODEL_FACTORY_INJECTIONS` are enabled. This means *all factories are extended* before being returned by the container. So every time you have a new container, you have a new factory (though it looks and behaves the same).

This change gets rid of that cache on meta. Instead it creates a function that accepts the store and meta, and returns the relationship object expected throughout Ember-Data. Two alternatives were considered:

1. Always check against `typeKey` instead of `instanceof`, but this felt like a dodge of the real problem and would leave the issue for others to find, or
2. Create a new first-class relationship object, but this would be a far more invasive change, and would impact much of the codebase that the current relationship object has already leaked through.

Additionally, the types were being cached on model class-level CPs. For this patch, those have simply been marked `cacheable(false)`. A later patch should refactor the CPs out of the way, or at least re-write their consumers to expect a relationship object without the factory itself already fetched.