Skip to content

Don't warn for 'async: false' relationships with link + data - #4599

Merged
bmac merged 2 commits into
warp-drive-data:masterfrom
wecc:improve-updateLink-warning
Nov 21, 2016
Merged

Don't warn for 'async: false' relationships with link + data#4599
bmac merged 2 commits into
warp-drive-data:masterfrom
wecc:improve-updateLink-warning

Conversation

@wecc

@wecc wecc commented Oct 19, 2016

Copy link
Copy Markdown
Contributor

This PR moves most of the code from store.setupRelationships() to relationship.push() to be able to set the hasData and hasLoaded flags correctly depending on both data and links in the payload.

relationship.push() will also allow us to push the contents from a relationship's self link in the future.

Fixes #3393

@wecc

wecc commented Oct 19, 2016

Copy link
Copy Markdown
Contributor Author

@wecc
wecc force-pushed the improve-updateLink-warning branch 4 times, most recently from beff34d to 64640f5 Compare October 20, 2016 11:59
@wecc

wecc commented Oct 20, 2016

Copy link
Copy Markdown
Contributor Author

Since moving code from store.setupRelationships() to relationship.push() didn't really have to do with the warning (it was just needed to be able to be smarter about the hasData and hasLoaded flag, so that the warning in turn could look at the hasData flag) i split it into two different commits.


BelongsToRelationship.prototype.updateData = function(data) {
// If the data contains a relationship that is specified as an ID,
// `deserializeRecordId()` will convert it into an DS.Model instance

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/DS.Model instance/InternalModel/


ManyRelationship.prototype.updateData = function(data) {
// If the data contains a relationship that is specified as IDs,
// `deserializeRecordIds()` will convert them to DS.Model instances

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

^

}
},

updateData: Ember.K

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ember.K shouldn't be used anymore. Either function() {} or remove completely, since it's defined in the subclasses anyhow...

@wecc
wecc force-pushed the improve-updateLink-warning branch 2 times, most recently from 6beab0f to 8c0cd0c Compare October 20, 2016 13:32
isNone
} = Ember;

export function convertResourceObjectToInternalModel(store, key, relationship, id) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It feels to me that this seems like a method that belongs to the store?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not really converting, it's also pushing right?

if (hasData) {
this.setHasData(true);
this.setHasLoaded(true);
} else if (hasLink) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like if you push the same link twice, this will say hasLoaded is false now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also added a test to cover this

@wecc
wecc force-pushed the improve-updateLink-warning branch 3 times, most recently from b1e7032 to 0ebac3e Compare October 21, 2016 20:38

// Pushing new data to the relationship might contain only data or links or
// a combination of both. Depending on what we pushed we need to set the
// hasData and hasLoaded flags accordingly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment might be better if it explains the logic & intentions behind doing this instead of saying accordingly

Comment thread addon/-private/system/store.js Outdated
if (isNone(ids)) {
return;
}
_pushResourceObjectsToStore(relationship, ids) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These aren't ids anymore right?

Comment thread addon/-private/system/store.js Outdated
if (isNone(id)) {
return;
}
_pushResourceObjectToStore(relationship, id) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not an id anymore

@wecc
wecc force-pushed the improve-updateLink-warning branch from 0ebac3e to 468419c Compare October 22, 2016 02:21
@wecc wecc mentioned this pull request Oct 22, 2016
Comment thread addon/-private/system/store.js Outdated
if (isNone(id)) {
return;
}
_pushResourceIdentity(relationship, resourceIdentity) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resource Identifier, not Resource Identity

Comment thread addon/-private/system/store.js Outdated
if (isNone(ids)) {
return;
}
_pushResourceIdentities(relationship, resourceIdentities) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resource Identifiers, not Resource Identities

@bmac

bmac commented Nov 16, 2016

Copy link
Copy Markdown
Contributor

@wecc do you have time to fix the variable names you commented on?

@wecc
wecc force-pushed the improve-updateLink-warning branch from 468419c to ce4eec6 Compare November 21, 2016 13:13
@wecc
wecc force-pushed the improve-updateLink-warning branch from ce4eec6 to 6133c88 Compare November 21, 2016 13:23
};

ManyRelationship.prototype.updateData = function(data) {
let internalModels = this.store._pushResourceIdentities(this, data);

@bmac bmac Nov 21, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let internalModel = this.store._pushResourceIdentifiers(this, data);

@wecc
wecc force-pushed the improve-updateLink-warning branch from 6133c88 to 9817170 Compare November 21, 2016 14:17
@bmac
bmac merged commit ea16bb6 into warp-drive-data:master Nov 21, 2016
@bmac

bmac commented Nov 21, 2016

Copy link
Copy Markdown
Contributor

Thanks @wecc 🎉

@pcambra

pcambra commented Nov 22, 2016

Copy link
Copy Markdown

I have updated ember-data to 2.10-beta3 and applied this PR in my environment and now I'm getting:

You pushed a record of type 'X' with a relationship 'Y' configured as 'async: false'. You've included a link but no primary data, this may be an error in your payload.

(The last bit is new)
Not sure what's wrong as data is displayed correctly and the jsonapi resource looks OK?

@bmac

bmac commented Jan 11, 2017

Copy link
Copy Markdown
Contributor

Hi @pcambra sorry for the late response. As you have discovered this pr was not included in Ember Data 2.10. The first release that includes this code is Ember Data 2.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants