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 adapter findHasMany #2252

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you changed the type into a relationship in the HasMany, but not in the belongsTo? Also test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorT I didn't need to change it because the relationship parameter is already passed in: https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store.js#L1788, and the tests already check for it: https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/relationships/belongs_to_test.js#L178 or am I missing something here?

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,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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanna assert that the relationship is passed in here correctly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorT looks better now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorT should I squash the two commits?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squashing would be nice 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorT I'm going to open a new PR with the squashed commits, will post here the new PR


return Ember.RSVP.resolve([
Expand All @@ -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" },
Expand Down