-
-
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
RESTSerializer.serializePolymorphicType
broken for async
relationships
#2508
Comments
I just noticed that |
I suspect the fact that |
@martinmaillard it seems like you have a good understanding of the problem and this definitely seems like a bug. Would you be comfortable submitting a pr to fix this issue with a test case? |
I'll see what I can do once I've checked how the new beta version behaves. I'm not sure I've got such a good understanding of the internals yet... |
I started writing the tests for this issue and it made me realize that I don't know what the normal behavior should be. I see two cases for an
In the first case, the record can be extracted from the promise and the polymorphicType property can be serialized as usual. In the second case, I'm not sure. It does not seem like a good idea to load the record just to serialize its parent. Can we access the original payload of the parent record and extract the original polymorphicType property from it ? |
I believe this is also related #2342 (comment) |
@martinmaillard Hm, I didn't get the bug in #1535 was because of polymorphism, and I thought it was just a matter of async relation, which seem to work, considering this test passes. @chadhietala #2342 seems yet an other one, caused by polymorphism and MODEL_FACTORY_INJECTION, which I think basically broke polymorphism in ember-cli app. |
Here's a hacky workaround in CoffeeScript... but it requires you to make sure that the async is fulfilled before you try to serialize it. serializePolymorphicType: (record, json, relationship) ->
key = relationship.key
belongsTo = record.get(key)
# hack for async
if belongsTo.constructor == DS.PromiseObject
if belongsTo.get('isFulfilled')
belongsTo = belongsTo.get('content')
else
throw Error("Unable to get belongsTo for relation that isn't fulfilled")
key = if @keyForAttribute then this.keyForAttribute(key) else key
if Ember.isNone(belongsTo)
json[key + "_type"] = null
else
json[key + "_type"] = Ember.String.classify(belongsTo.constructor.typeKey) |
Should be fixed by #2623 |
When a relationship is defined as
polymorphic
andasync
,serializePolymorphicType
raiseskey is undefined
because the related object is wrapped in a promise, which breaksbelongsTo.constructor.typeKey
.The text was updated successfully, but these errors were encountered: