Skip to content

Commit

Permalink
Merge pull request emberjs#1257 from dandehavilland/missing-resolver-…
Browse files Browse the repository at this point in the history
…on-many-array

Added missing resovler definition on DS.ManyArray
  • Loading branch information
wycats committed Sep 10, 2013
2 parents 9708f2e + a316773 commit 0d4317c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/ember-data/lib/system/record_arrays/many_array.js
Expand Up @@ -82,10 +82,11 @@ DS.ManyArray = DS.RecordArray.extend({
fetch: function() {
var records = get(this, 'content'),
store = get(this, 'store'),
owner = get(this, 'owner');
owner = get(this, 'owner'),
resolver = Ember.RSVP.defer();

var unloadedRecords = records.filterProperty('isEmpty', true);
store.fetchMany(unloadedRecords, owner);
store.fetchMany(unloadedRecords, owner, resolver);
},

// Overrides Ember.Array's replace method to implement
Expand Down
47 changes: 47 additions & 0 deletions packages/ember-data/tests/integration/adapter/rest_adapter_test.js
Expand Up @@ -240,6 +240,53 @@ test("create - a serializer's attributes are consulted when building the payload
}));
});

test("create - a record on the many side of a hasMany relationship should update relationships when data is sideloaded", function() {
expect(3);

ajaxResponse({
posts: [{
id: "1",
name: "Rails is omakase",
comments: [1,2]
}],
comments: [{
id: "1",
name: "Dat Parley Letter",
post: 1
},{
id: "2",
name: "Another Comment",
post: 1
}]
// My API is returning a comment:{} as well as a comments:[{...},...]
//, comment: {
// id: "2",
// name: "Another Comment",
// post: 1
// }
});

Post.reopen({ comments: DS.hasMany('comment') });
Comment.reopen({ post: DS.belongsTo('post') });

store.push('post', { id: 1, name: "Rails is omakase", comments: [1] });
store.push('comment', { id: 1, name: "Dat Parlay Letter", post: 1 });

var post = store.getById('post', 1);
var commentCount = post.get('comments.length');
equal(commentCount, 1, "the post starts life with a comment");

var comment = store.createRecord('comment', { name: "Another Comment", post: post });

comment.save().then(async(function(comment) {
equal(comment.get('post'), post, "the comment is related to the post");
}));

post.reload().then(async(function(post) {
equal(post.get('comments.length'), 2, "Post comment count has been updated");
}));
});

test("update - an empty payload is a basic success", function() {
store.push('post', { id: 1, name: "Rails is omakase" });

Expand Down

0 comments on commit 0d4317c

Please sign in to comment.