-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[bugfix beta] Add inverse relationship on payload when missing #5608
Merged
runspired
merged 8 commits into
master
from
add-inverse-relationship-on-payload-when-missing/fivetanley
Oct 3, 2018
Merged
[bugfix beta] Add inverse relationship on payload when missing #5608
runspired
merged 8 commits into
master
from
add-inverse-relationship-on-payload-when-missing/fivetanley
Oct 3, 2018
Commits on Oct 2, 2018
-
Configuration menu - View commit details
-
Copy full SHA for 9540b30 - Browse repository at this point
Copy the full SHA 9540b30View commit details -
push leftHandSide relationship info for findHasMany/belongsTo
always pushes the left hand side of a relationship, even when the adapter does not return a payload with the left hand side's ids in `relationships`. What a mouthful. Let's unpack that. Given the following model definitions: ```javascript // app/models/person.js export default DS.Model.extend({ name: attr(), dogs: hasMany('dog', { async: true }) }); ``` ```javascript // app/models/dog.js export default DS.Model.extend({ name: attr(), person: belongsTo('person', { async: true }) }); ``` Given `PersonAdapter#findRecord` returns the following payload and is pushed into the store: ```javascript const payload = { data: { type: 'person', id: '1', attributes: { name: 'John Churchill' }, relationships: { dogs: { links: { related: 'http://exmaple.com/person/1/dogs' } } } } }; ``` and the result of `DogAdapter#findHasMany` resolves with the following payload: ```javascript { data: [ { id: 1, type: 'dog', attributes: { name: 'Scooby' } }, { id: 2, type: 'dog', attributes: { name: 'Scrappy' } } ] } ``` Notice how the payload for `DogAdapter#findHasMany` does not have a `relationships` key for any of the returned dogs. This is technically valid JSONAPI, but in today's Ember Data, *for explicit inverses only* (notice how we specified 'person' on the Dog model; an implicit relationship would be generated for us if we left it out and used internally for tracking various things), the inverse relationship does not get set up. For example, `dog.get('person.id')` would still be null when it should be `1` (the `id` of the Person it belongsTo). This commit fixes that by always pushing the inverse relationship using the store's RelationshipPayloadsManager. In this example, the following relationship info is pushed: ```javascript { data: { id: '1', type: 'person' } } ``` This makes the result of requesting `DogAdapter#findHasMany` effectively the following payload: ```javascript { data: [ { id: 1, type: 'dog', attributes: { name: 'Scooby' }, relationships: { id: '1', type: 'person' } }, { id: 2, type: 'dog', attributes: { name: 'Scrappy' }, relationships: { id: '1', type: 'person' } } ] } ``` Adding this information makes the relationships line up correctly.
Configuration menu - View commit details
-
Copy full SHA for e7b45e2 - Browse repository at this point
Copy the full SHA e7b45e2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5b6c5d4 - Browse repository at this point
Copy the full SHA 5b6c5d4View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2ff7965 - Browse repository at this point
Copy the full SHA 2ff7965View commit details -
Configuration menu - View commit details
-
Copy full SHA for be3dc16 - Browse repository at this point
Copy the full SHA be3dc16View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8344c66 - Browse repository at this point
Copy the full SHA 8344c66View commit details
Commits on Oct 3, 2018
-
Configuration menu - View commit details
-
Copy full SHA for 451183f - Browse repository at this point
Copy the full SHA 451183fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 7aa4499 - Browse repository at this point
Copy the full SHA 7aa4499View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.