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

polmorphic hasMany is not deserializing as correct type #1141

Closed
lukegalea opened this issue Sep 1, 2013 · 5 comments
Closed

polmorphic hasMany is not deserializing as correct type #1141

lukegalea opened this issue Sep 1, 2013 · 5 comments

Comments

@lukegalea
Copy link

We have a form that has many elements. The has many association is polymorphic: true, but the corresponding belongs to is not as elements can only belong to a form.

There are several models that extend element (text and text area for instance).

All is well creating new text elements and adding to the elements array and saving, but when loading the data, all the elements are being deserialized as their base class (element).

Currently the form json contains element_ids, and a GET is triggered with the list of ids. This response contains a mix of different types, so the 'type' field is included in the response payload for each element.

How can Ember-Data be made to deserialize these into the correct classes?

@hjdivad
Copy link
Member

hjdivad commented Sep 1, 2013

cc @cyril-sf

@lukegalea
Copy link
Author

@Cyrl-sf @hjdivad I just saw this: #750

I realize now that my payload needs to look like this:
{
"form": {
"id": 1,
"elements": [{"id": 1, "type": "text_element"}]
}
}

Just fighting with ActiveModel::Serializer to see if I can get that going now. Will close issue as soon as I can confirm.

@lukegalea
Copy link
Author

Got it! elements_id rather than elements, but regardless.. all good. Thanks @hjdivad. Your cc of Cyril-sf lead me to that PR, which had everything I needed.

@hjdivad
Copy link
Member

hjdivad commented Sep 1, 2013

No worries @lukegalea. Great job @cyril-sf: you seem to have fixed the problem without even showing up. wuwei.

@cyril-sf
Copy link
Contributor

cyril-sf commented Sep 1, 2013

@lukegalea Great! Let us know if you have questions

@hjdivad I like to solve problems in my sleep.

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