Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back relationship parameter for findHasMany & findBelongsTo #2263

Merged
merged 1 commit into from
Sep 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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