-
Notifications
You must be signed in to change notification settings - Fork 30
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
Breaks polymorphic relationships in Ember Data #25
Comments
I feel like this could be a simple fix. Is there a way to detect if the object is polymorphic? |
This could probably be solved by reflecting on the association. |
It seems this was fixed in emberjs/data#1662 so |
Adding proper support for polymorphic associations also requires mangling the content of the type column. Example: module Foo
class Asset
belongs_to :viewable
end
class User
end
class AssetSerializer
embed :ids, include: true
attributes :id
has_one :viewable, polymorphic: true
end
class UserSerializer
attributes :id
end
end
user = Foo::User.create
=> #<Foo::User id:1>
asset = Foo::Asset.create(viewable: user)
=> #<Foo::Asset id:1, viewable_id: 1, viewable_type: "Foo::User">
Foo::AssetSerializer.new(asset).as_json
=> {:users=> [{:id=>1}], :asset=>{:id=>1, :viewable=>{:type=>:user, :id=>1}}} Resulting JSON: {
"users" : [
{
"id" : 1
}
],
"asset" : {
"id" : 1,
"viewable" : {
"type" : "user",
"id" : 1
}
}
} As can be seen, AMS removes the module names from the types and changes them to underscored notation. |
With postgres_ext-serializers installed polymorphic relationships are serialized as:
Which ember data does not support: emberjs/data#1574
Without postgres_ext-serializers installed polymorphic relationships are serialized as:
Which ember data does support.
The text was updated successfully, but these errors were encountered: