-
-
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
fixes serializeHasMany relationshipType #1678
Conversation
@fsmanuel this is failing in travis, also could you please add tests for this? |
I agree that it seems like a typo, but apparently https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/changes/relationship_change.js#L89 |
@rjackson wonder though about the |
it seems to be intentional that there is no manyToOne. i added a test for my concern but |
@abuiles added a test and fixed the failing |
@@ -391,9 +391,9 @@ DS.JSONSerializer = Ember.Object.extend({ | |||
|
|||
var relationshipType = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship); | |||
|
|||
if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany') { | |||
if (relationshipType === 'manyToNone' || relationshipType === 'manyToOne' || relationshipType === 'manyToMany') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All three are needed, how about:
var relationshipTypes = ['manyToNone', 'manyToMany', 'manyToOne'];
if (relationshipTypes.indexOf(relationshipType) > -1) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't know which one is faster. but yours seems cleaner.
👍 |
1 similar comment
👍 |
OneToMany are not serialized by default, because the JSON serializer assumes by default that you would save your id's as foreign keys on the child. If you need to serialize them, you can now instead of editing the serializeHasMany code, apply the EmbeddedRecordsMixin and say
I do think this is a bit non obvious, would be nice to document it better. |
@igorT thanks for the clarification and your work on ember-data. will try the attrs approach tomorrow. wasn't aware of the possibility. |
there is a typo in the JSONSerializer serializeHasMany that prevents hasMany relations from getting serialized.