Skip to content

Commit

Permalink
Refactor relationship handling code
Browse files Browse the repository at this point in the history
This commit refactors relationship handling code. It adds full
support for loading relationships described on only one side in the
api. It sets up the infrastructure for separting server vs local
updates to relationships. In a future PR, we will use that infrastructure
to add support for rollback, relationship dirtying and relationship merging.

Lots of old, crappy code, removed, -550 lines before new tests.
Pushing records into the store is now 15-20% faster.
Relationships now properly refetch if the links value is updated.
We no longer churn records that are not changed in a hasMany push.

fixes #1919 fixes #1814 fixes #2057 fixes #2191 fixes #2177
fixes #2125 fixes #2100 fixes #1790 fixes #1532 fixes #1389
  • Loading branch information
igorT committed Sep 5, 2014
1 parent 959bfa2 commit 3fb60d5
Show file tree
Hide file tree
Showing 28 changed files with 1,420 additions and 1,206 deletions.
24 changes: 3 additions & 21 deletions packages/ember-data/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,18 @@ import DS from "ember-data/core";
import "ember-data/ext/date";

import {
Store,
PromiseArray,
PromiseObject
} from "ember-data/system/promise_proxies";
import {
Store
} from "ember-data/system/store";
import {
Model,
Errors,
RootState,
attr
} from "ember-data/system/model";
import {
AttributeChange,
RelationshipChange,
RelationshipChangeAdd,
RelationshipChangeRemove,
OneToManyChange,
ManyToNoneChange,
OneToOneChange,
ManyToManyChange
} from "ember-data/system/changes";
import {
InvalidError,
Adapter
Expand Down Expand Up @@ -80,16 +72,6 @@ DS.RootState = RootState;
DS.attr = attr;
DS.Errors = Errors;

DS.AttributeChange = AttributeChange;
DS.RelationshipChange = RelationshipChange;
DS.RelationshipChangeAdd = RelationshipChangeAdd;
DS.RelationshipChangeRemove = RelationshipChangeRemove;
DS.ManyToNoneChange = ManyToNoneChange;
DS.OneToManyChange = OneToManyChange;
DS.ManyToNoneChange = OneToManyChange;
DS.OneToOneChange = OneToOneChange;
DS.ManyToManyChange = ManyToManyChange;

DS.Adapter = Adapter;
DS.InvalidError = InvalidError;

Expand Down
3 changes: 1 addition & 2 deletions packages/ember-data/lib/serializers/json_serializer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { RelationshipChange } from "ember-data/system/changes";
var get = Ember.get;
var isNone = Ember.isNone;
var map = Ember.ArrayPolyfills.map;
Expand Down Expand Up @@ -633,7 +632,7 @@ export default Ember.Object.extend({
payloadKey = this.keyForRelationship(key, "hasMany");
}

var relationshipType = RelationshipChange.determineRelationshipType(record.constructor, relationship);
var relationshipType = record.constructor.determineRelationshipType(relationship);

if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany') {
json[payloadKey] = get(record, key).mapBy('id');
Expand Down
23 changes: 0 additions & 23 deletions packages/ember-data/lib/system/changes.js

This file was deleted.

Loading

0 comments on commit 3fb60d5

Please sign in to comment.