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

extractPolymorphicRelationship method is not called when extracting a polymorphic hasMany relationship #5623

Closed
ehaberev opened this issue Sep 4, 2018 · 3 comments

Comments

@ehaberev
Copy link

ehaberev commented Sep 4, 2018

Why polymorphic option is checking only for belongsTo relationships when extracting relationships in DS.JSONSerializer (and in DS.RESTSeriazlizer correspondingly)?

I need set proper value for type property in relationship hashes for plymorphic hasMany embedded records (in my case I have @odata.type property in hash and I need to convert it to type property with appropriate value), otherwise error will be thrown in _normalizeEmbeddedRelationship method of DS.EmbeddedRecordsMixin when extracting these relationship hashes.

My serializers are inherited from DS.RESTSerializer, but I can't use neither keyForPolymorphicType hook nor extractPolymorphicRelationship method to specify a custom type key for polymorphic hasMany relationship, because it is called only for belongsTo polymorphic records.

So is there a right way to do this? Or what is a right way to customize extracting polymorphic hasMany relationships (some analogue of extractPolymorphicRelationship method)?

It seems there is no documentation for this case.

@runspired
Copy link
Contributor

Seems like an oversight, feel free to PR a fix.

@Parrryy
Copy link
Contributor

Parrryy commented Oct 1, 2018

I wouldn't mind picking this up for Hacktoberfest. I'm assuming it's a case of adding the extractPolymorphicRelationship with check to hasMany for each data item?

@runspired
Copy link
Contributor

@Parrryy thanks! and yes:

https://github.com/emberjs/data/blob/v3.3.1/addon/serializers/json.js#L678 here we would make the same conditional branch as the belongs-to based on whether we are polymorphic. I would recommend caching the check for whether we are polymorphic somewhere outside of the loop.

Parrryy added a commit to Parrryy/data that referenced this issue Oct 4, 2018
…ny (emberjs#5623)

Added conditional check to extract polymorphic relationship for hasMany (emberjs#5623)

Added extract polymorphic for hasMany relationship
runspired added a commit that referenced this issue Oct 4, 2018
Added check to extract polymorphic relationship for hasMany (#5623)
runspired pushed a commit that referenced this issue Oct 26, 2018
…ny (#5623)

Added conditional check to extract polymorphic relationship for hasMany (#5623)

Added extract polymorphic for hasMany relationship
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

No branches or pull requests

3 participants