From 1e8a256ba26862b5bf2a3aae16b2a62458acd3f9 Mon Sep 17 00:00:00 2001 From: "Alessandro D'Aquino (elara)" Date: Mon, 8 Sep 2014 17:07:23 +0200 Subject: [PATCH 1/2] Bring back relationship parameter for adapter findHasMany Signed-off-by: Alessandro D'Aquino (elara) --- packages/ember-data/lib/adapters/rest_adapter.js | 4 ++-- .../lib/system/relationships/relationship.js | 2 +- packages/ember-data/lib/system/store.js | 14 +++++++------- .../integration/relationships/has_many_test.js | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/ember-data/lib/adapters/rest_adapter.js b/packages/ember-data/lib/adapters/rest_adapter.js index 7b4bf67ac5..8ef73a7ada 100644 --- a/packages/ember-data/lib/adapters/rest_adapter.js +++ b/packages/ember-data/lib/adapters/rest_adapter.js @@ -392,7 +392,7 @@ export default Adapter.extend({ @param {String} url @return {Promise} promise */ - findHasMany: function(store, record, url) { + findHasMany: function(store, record, url, relationship) { var host = get(this, 'host'); var id = get(record, 'id'); var type = record.constructor.typeKey; @@ -431,7 +431,7 @@ export default Adapter.extend({ @param {String} url @return {Promise} promise */ - findBelongsTo: function(store, record, url) { + findBelongsTo: function(store, record, url, relationship) { var id = get(record, 'id'); var type = record.constructor.typeKey; diff --git a/packages/ember-data/lib/system/relationships/relationship.js b/packages/ember-data/lib/system/relationships/relationship.js index a3e3cf19b3..2d66b921ad 100644 --- a/packages/ember-data/lib/system/relationships/relationship.js +++ b/packages/ember-data/lib/system/relationships/relationship.js @@ -138,7 +138,7 @@ ManyRelationship.prototype.getRecords = function() { var self = this; var promise; if (this.link && !this.hasFetchedLink) { - promise = this.store.findHasMany(this.record, this.link, this.belongsToType).then(function(records){ + promise = this.store.findHasMany(this.record, this.link, this.relationshipMeta).then(function(records){ self.updateRecordsFromAdapter(records); self.hasFetchedLink = true; //TODO(Igor) try to abstract the isLoaded part diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index 910921a9df..c9c932fdc9 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -1765,23 +1765,23 @@ function _findMany(adapter, store, type, ids, records) { }, null, "DS: Extract payload of " + type); } -function _findHasMany(adapter, store, record, link, type) { - var promise = adapter.findHasMany(store, record, link); - var serializer = serializerForAdapter(adapter, type); - var label = "DS: Handle Adapter#findHasMany of " + record + " : " + type; +function _findHasMany(adapter, store, record, link, relationship) { + var promise = adapter.findHasMany(store, record, link, relationship); + var serializer = serializerForAdapter(adapter, relationship.type); + var label = "DS: Handle Adapter#findHasMany of " + record + " : " + relationship.type; promise = Promise.cast(promise, label); promise = _guard(promise, _bind(_objectIsAlive, store)); promise = _guard(promise, _bind(_objectIsAlive, record)); return promise.then(function(adapterPayload) { - var payload = serializer.extract(store, type, adapterPayload, null, 'findHasMany'); + var payload = serializer.extract(store, relationship.type, adapterPayload, null, 'findHasMany'); Ember.assert("The response from a findHasMany must be an Array, not " + Ember.inspect(payload), Ember.typeOf(payload) === 'array'); - var records = store.pushMany(type, payload); + var records = store.pushMany(relationship.type, payload); return records; - }, null, "DS: Extract payload of " + record + " : hasMany " + type); + }, null, "DS: Extract payload of " + record + " : hasMany " + relationship.type); } function _findBelongsTo(adapter, store, record, link, relationship) { diff --git a/packages/ember-data/tests/integration/relationships/has_many_test.js b/packages/ember-data/tests/integration/relationships/has_many_test.js index b8cf3d1ced..8dd68da714 100644 --- a/packages/ember-data/tests/integration/relationships/has_many_test.js +++ b/packages/ember-data/tests/integration/relationships/has_many_test.js @@ -99,7 +99,7 @@ test("A serializer can materialize a hasMany as an opaque token that can be lazi throw new Error("Adapter's findMany should not be called"); }; - env.adapter.findHasMany = function(store, record, link) { + env.adapter.findHasMany = function(store, record, link, relationship) { equal(link, "/posts/1/comments", "findHasMany link was /posts/1/comments"); return Ember.RSVP.resolve([ @@ -123,7 +123,7 @@ test("An updated `links` value should invalidate a relationship cache", function comments: DS.hasMany('comment', { async: true }) }); - env.adapter.findHasMany = function(store, record, link) { + env.adapter.findHasMany = function(store, record, link, relationship) { if (link === '/first') { return Ember.RSVP.resolve([ { id: 1, body: "First" }, From 51208c3f95e884daa9ee1e6226d68cf3477843d3 Mon Sep 17 00:00:00 2001 From: "Alessandro D'Aquino (elara)" Date: Mon, 8 Sep 2014 17:32:35 +0200 Subject: [PATCH 2/2] Added missing tests for brought back parameter relationship Signed-off-by: Alessandro D'Aquino (elara) --- .../tests/integration/relationships/has_many_test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/ember-data/tests/integration/relationships/has_many_test.js b/packages/ember-data/tests/integration/relationships/has_many_test.js index 8dd68da714..452d6b6b43 100644 --- a/packages/ember-data/tests/integration/relationships/has_many_test.js +++ b/packages/ember-data/tests/integration/relationships/has_many_test.js @@ -101,6 +101,7 @@ test("A serializer can materialize a hasMany as an opaque token that can be lazi env.adapter.findHasMany = function(store, record, link, relationship) { equal(link, "/posts/1/comments", "findHasMany link was /posts/1/comments"); + equal(relationship.type.typeKey, "comment", "relationship was passed correctly"); return Ember.RSVP.resolve([ { id: 1, body: "First" }, @@ -118,12 +119,14 @@ test("A serializer can materialize a hasMany as an opaque token that can be lazi }); test("An updated `links` value should invalidate a relationship cache", function() { - expect(6); + expect(8); Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); env.adapter.findHasMany = function(store, record, link, relationship) { + equal(relationship.type.typeKey, "comment", "relationship was passed correctly"); + if (link === '/first') { return Ember.RSVP.resolve([ { id: 1, body: "First" },