Skip to content

Commit

Permalink
Merge pull request #2263 from intuitivepixel/bring-back-relationship
Browse files Browse the repository at this point in the history
Bring back relationship parameter for findHasMany & findBelongsTo
  • Loading branch information
fivetanley committed Sep 9, 2014
2 parents a97b492 + 48e2a63 commit 430024f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/ember-data/lib/adapters/rest_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ 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");
equal(relationship.type.typeKey, "comment", "relationship was passed correctly");

return Ember.RSVP.resolve([
{ id: 1, body: "First" },
Expand All @@ -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) {
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" },
Expand Down

0 comments on commit 430024f

Please sign in to comment.