-
-
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
Fix #1492 and fall back to serializing records into IDs when not embedded. #1494
Conversation
… in function serializeHasMany The serializer did serialize manyToNone and manyToMany relationships. There is nothing to do in a manyToNone relationship. ManyToOne relationships weren't handled so I changed manyToNone into manyToOne
When `embedded: 'always'` AMS embeds records properly. Otherwise it skips the dependencies altogether. This commit makes AMS fall back to the default RESTSerializer and serialize records to an array of their IDs.
Could you also allow this functionality to run when As I understand it, it seems to be the same logic. |
@tstirrat, the fix is for serialization. |
It is my understanding that embedded 'load' means to extract embedded, but
|
What this PR does is fixing a problem that I've seen too many people talk about lately. @kaukas could you take a look again at this? It'd be very good to have this PR merged imo. |
I would love to see a merge of this, what's the hold up? 🐹 |
+1 |
@MartinElvar lack of time to review :( |
+1 |
Would be absolutely amazing to see this in release 1.0, this is ugently needed! |
+1 |
Here is a a quick fix for those of you who's in great need for a fix 😄 // Apply hack that fixes ManyToOne serialization.
// Use until this is merged, or fixed otherwise.
// https://github.com/emberjs/data/pull/1494
DS.ActiveModelSerializer.reopen({
serializeHasMany : function(record, json, relationship) {
var key = relationship.key;
var relationshipType = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship);
if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany' || relationshipType === 'manyToOne') {
var payloadKey = this.keyForRelationship ? this.keyForRelationship(key, "hasMany") : key;
json[payloadKey] = Ember.get(record, key).mapBy('id');
}
}
}); |
👍 |
Hi everyone! |
+1 for @MartinElvar fix above |
This was fixed with the merge of the better embedded records support thanks to @pixelhandler. You can now declare embedded: 'ids' in your attrs hash if you want to serialize the hasMany side. |
In
serializeHasMany
the JSONSerializer was trying to serializemanyToNone
relations (don't even know what that means) instead ofmanyToOne
. I found @hg-schneider had already fixed that with a pull request pending (#1488). I used it as a base for my changes.I had to modify other AMS integration tests to add empty arrays since
hasMany
is now serialized even when empty. Please review and confirm that this is correct and expected logic.