emberjs/data — pull request #1631 by mmpestorich (2014-01-07 04:53:58+00:00)
Title: Allow async relationship changes and rollbacks.

Most of my applications resolve relationships asynchronously. Before ember-data recently underwent a somewhat large refactor, resolving async relationships wasn't perfect but I was able to accomplish what I needed to using the various hooks available to me (such as materialize*, dirtyRecordFor*, etc...). However, with the recent refactor, most of those hooks are now gone, async relationship changes were effectively disabled and rolling back anything is basically broken. I had put off upgrading from pre-1.0 ember-data for as long as I could, but am at the point were I really need bring some of our applications current (which stand to gain a lot from recent releases of ember.js).

Anyway, here's my attempt at putting some of these things back into working condition. I believe that it conceptually falls in line with recent changes. At the very least this might help someone that needs to get by for the time being.

This commit provides for the following:
* Proper relationship changes for async relationships:
- Doesn't load a unloaded inverse if it doesn't have to
- (i.e. setting a belongsTo won't load an unloaded inverse hasMany)
- Relationship changes work right on newly created records
- Handles promises from async relationships properly
* Proper rollback of relationships.
* Refactored DS.hasMany and DS.belongsTo.
* Added _relationship to DS.belongsTo (similar to _attributes in DS.attr).
* Allow didSetProperty to work with belongsTo relationships in model states.
- belongsTos are basically no different than attributes so this handles them similarly
* Fixed a test that was passing with old code but was not actually right
- It was doing so only because async relationships weren't triggering any relationship changes
* Added a test to ensure undefined is always handled as null when setting an attribute value

Relationship changes now propagate correctly and model.rollback() works on both belongsTo and hasMany relationships. New tests, specific to async relationship changes and relationship rollbacks, still need to be written to verify that all this is working as intended. However, in my test application everything is working as I intended it too. In addition, nothing here breaks any existing behavior as this commit passes all current tests.