mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Serialize polymorphic id like a composite FK
This commit is contained in:
@@ -710,4 +710,28 @@ class SerializerTest < ActiveModel::TestCase
|
||||
}
|
||||
}, serializer.as_json)
|
||||
end
|
||||
|
||||
def test_polymorphic_has_one_with_ids
|
||||
polymorphic_blog = Class.new do
|
||||
attr_accessor :writer
|
||||
end
|
||||
|
||||
polymorphic_serializer = Class.new(ActiveModel::Serializer) do
|
||||
embed :ids
|
||||
has_one :writer, :polymorphic => true
|
||||
end
|
||||
|
||||
user = PolymorphicUser.new :id => 1
|
||||
blog = polymorphic_blog.new
|
||||
blog.writer = user
|
||||
|
||||
serializer = polymorphic_serializer.new(blog, user)
|
||||
|
||||
assert_equal({
|
||||
:writer => {
|
||||
:writer_type => 'PolymorphicUser',
|
||||
:id => 1
|
||||
}
|
||||
}, serializer.as_json)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user