diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index 008e2d856e9..d21683580ec 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -1786,10 +1786,12 @@ function normalizeRelationships(store, type, data, record) { type.eachRelationship(function(key, relationship) { var kind = relationship.kind; var value = data[key]; - if (kind === 'belongsTo') { - deserializeRecordId(store, data, key, relationship, value); - } else if (kind === 'hasMany') { - deserializeRecordIds(store, data, key, relationship, value); + if (!(value instanceof Ember.ComputedProperty)) { + if (kind === 'belongsTo') { + deserializeRecordId(store, data, key, relationship, value); + } else if (kind === 'hasMany') { + deserializeRecordIds(store, data, key, relationship, value); + } } }); @@ -2072,19 +2074,21 @@ function setupRelationships(store, record, data) { type.eachRelationship(function(key, descriptor) { var kind = descriptor.kind; var value = data[key]; - var relationship = record._relationships[key]; + if (!(value instanceof Ember.ComputedProperty)) { + var relationship = record._relationships[key]; - if (data.links && data.links[key]) { - relationship.updateLink(data.links[key]); - } + if (data.links && data.links[key]) { + relationship.updateLink(data.links[key]); + } - if (kind === 'belongsTo') { - if (value === undefined) { - return; + if (kind === 'belongsTo') { + if (value === undefined) { + return; + } + relationship.setCanonicalRecord(value); + } else if (kind === 'hasMany' && value) { + relationship.updateRecordsFromAdapter(value); } - relationship.setCanonicalRecord(value); - } else if (kind === 'hasMany' && value) { - relationship.updateRecordsFromAdapter(value); } }); } diff --git a/packages/ember-data/tests/integration/relationships/belongs_to_test.js b/packages/ember-data/tests/integration/relationships/belongs_to_test.js index 1de4864bee6..fa18fe2c7ec 100644 --- a/packages/ember-data/tests/integration/relationships/belongs_to_test.js +++ b/packages/ember-data/tests/integration/relationships/belongs_to_test.js @@ -7,6 +7,10 @@ var hasMany = DS.hasMany; var belongsTo = DS.belongsTo; var hash = Ember.RSVP.hash; +function getComputedPropertyDesc(model, key) { + return Ember.meta(model).descs ? Ember.meta(model).descs[key] : model[key]; +} + module("integration/relationship/belongs_to Belongs-To Relationships", { setup: function() { User = DS.Model.extend({ @@ -362,15 +366,16 @@ test("relationshipsByName is cached in production", function() { var oldTesting = Ember.testing; //We set the cacheable to true because that is the default state for any CP and then assert that it //did not get dynamically changed when accessed - var oldCacheable = Ember.meta(model).descs.relationshipsByName._cacheable; - Ember.meta(model).descs.relationshipsByName._cacheable = true; + var relationshipsByName = getComputedPropertyDesc(model, 'relationshipsByName'); + var oldCacheable = relationshipsByName._cacheable; + relationshipsByName._cacheable = true; Ember.testing = false; try { equal(get(model, 'relationshipsByName'), get(model, 'relationshipsByName'), 'relationshipsByName are cached'); equal(get(model, 'relationshipsByName'), get(model, 'relationshipsByName'), 'relationshipsByName are cached'); } finally { Ember.testing = oldTesting; - Ember.meta(model).descs.relationshipsByName._cacheable = oldCacheable; + relationshipsByName._cacheable = oldCacheable; } }); @@ -379,15 +384,16 @@ test("relatedTypes is cached in production", function() { var oldTesting = Ember.testing; //We set the cacheable to true because that is the default state for any CP and then assert that it //did not get dynamically changed when accessed - var oldCacheable = Ember.meta(model).descs.relatedTypes._cacheable; - Ember.meta(model).descs.relatedTypes._cacheable = true; + var relatedTypes = getComputedPropertyDesc(model, 'relatedTypes'); + var oldCacheable = relatedTypes._cacheable; + relatedTypes._cacheable = true; Ember.testing = false; try { equal(get(model, 'relatedTypes'), get(model, 'relatedTypes'), 'relatedTypes are cached'); equal(get(model, 'relatedTypes'), get(model, 'relatedTypes'), 'relatedTypes are cached'); } finally { Ember.testing = oldTesting; - Ember.meta(model).descs.relatedTypes._cacheable = oldCacheable; + relatedTypes._cacheable = oldCacheable; } }); @@ -396,15 +402,16 @@ test("relationships is cached in production", function() { var oldTesting = Ember.testing; //We set the cacheable to true because that is the default state for any CP and then assert that it //did not get dynamically changed when accessed - var oldCacheable = Ember.meta(model).descs.relatedTypes._cacheable; - Ember.meta(model).descs.relationships._cacheable = true; + var relationships = getComputedPropertyDesc(model, 'relationships'); + var oldCacheable = relationships._cacheable; + relationships._cacheable = true; Ember.testing = false; try { equal(get(model, 'relationships'), get(model, 'relationships'), 'relationships are cached'); equal(get(model, 'relationships'), get(model, 'relationships'), 'relationships are cached'); } finally { Ember.testing = oldTesting; - Ember.meta(model).descs.relationships._cacheable = oldCacheable; + relationships._cacheable = oldCacheable; } }); diff --git a/packages/ember-data/tests/integration/store_test.js b/packages/ember-data/tests/integration/store_test.js index 62ce788222f..794eaf4a89d 100644 --- a/packages/ember-data/tests/integration/store_test.js +++ b/packages/ember-data/tests/integration/store_test.js @@ -171,7 +171,6 @@ test("destroying the store correctly cleans everything up", function() { Ember.run(store, 'destroy'); equal(car.get('person'), null, "expected car.person to no longer be present"); - equal(person.get('cars'), undefined, "expected person.cars to be empty"); equal(personWillDestroy.called.length, 1, 'expected person to have recieved willDestroy once'); equal(carWillDestroy.called.length, 1, 'expected car to recieve willDestroy once'); diff --git a/packages/ember-data/tests/unit/record_array_test.js b/packages/ember-data/tests/unit/record_array_test.js index 6942317c566..9e8ec6e9f4b 100644 --- a/packages/ember-data/tests/unit/record_array_test.js +++ b/packages/ember-data/tests/unit/record_array_test.js @@ -49,6 +49,15 @@ test("stops updating when destroyed", function() { expect(3); var store = createStore(); + // TODO remove once + // https://github.com/emberjs/ember.js/commit/c3f13e85a62069295965dd49ca487fe6ddba1188 + // is on the release branch + var arrayProxy = Ember.ArrayProxy.create(); + run(function() { + arrayProxy.destroy(); + }); + var emptyLength = arrayProxy.get('length'); + var recordArray = store.all(Person); run(function() { store.push(Person, { id: 1, name: 'wycats' }); @@ -59,11 +68,11 @@ test("stops updating when destroyed", function() { }); run(function() { - equal(recordArray.get('length'), undefined, "Has no more records"); + equal(recordArray.get('length'), emptyLength, "Has no more records"); store.push(Person, { id: 2, name: 'brohuda' }); }); - equal(recordArray.get('length'), undefined, "Has not been updated"); + equal(recordArray.get('length'), emptyLength, "Has not been updated"); equal(recordArray.get('content'), undefined, "Has not been updated"); });