mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
Easier to work with polymorphic interface
This commit is contained in:
parent
655c4fe1c2
commit
38859d1f3d
@ -267,7 +267,10 @@ module ActiveModel
|
|||||||
object = associated_object
|
object = associated_object
|
||||||
|
|
||||||
if object && polymorphic?
|
if object && polymorphic?
|
||||||
{ polymorphic_key => find_serializable(object).serializable_hash }
|
{
|
||||||
|
:type => polymorphic_key,
|
||||||
|
polymorphic_key => find_serializable(object).serializable_hash
|
||||||
|
}
|
||||||
elsif object
|
elsif object
|
||||||
find_serializable(object).serializable_hash
|
find_serializable(object).serializable_hash
|
||||||
end
|
end
|
||||||
@ -283,7 +286,10 @@ module ActiveModel
|
|||||||
object = associated_object
|
object = associated_object
|
||||||
|
|
||||||
if object && polymorphic?
|
if object && polymorphic?
|
||||||
{ polymorphic_key => object.read_attribute_for_serialization(:id) }
|
{
|
||||||
|
:type => polymorphic_key,
|
||||||
|
:id => object.read_attribute_for_serialization(:id)
|
||||||
|
}
|
||||||
elsif object
|
elsif object
|
||||||
object.read_attribute_for_serialization(:id)
|
object.read_attribute_for_serialization(:id)
|
||||||
else
|
else
|
||||||
|
|||||||
@ -1025,6 +1025,7 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
:name => 'logo.png',
|
:name => 'logo.png',
|
||||||
:url => 'http://example.com/logo.png',
|
:url => 'http://example.com/logo.png',
|
||||||
:attachable => {
|
:attachable => {
|
||||||
|
:type => :email,
|
||||||
:email => { :subject => 'foo', :body => 'bar' }
|
:email => { :subject => 'foo', :body => 'bar' }
|
||||||
}
|
}
|
||||||
}, actual)
|
}, actual)
|
||||||
@ -1061,7 +1062,8 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
:name => 'logo.png',
|
:name => 'logo.png',
|
||||||
:url => 'http://example.com/logo.png',
|
:url => 'http://example.com/logo.png',
|
||||||
:attachable => {
|
:attachable => {
|
||||||
:email => 1
|
:type => :email,
|
||||||
|
:id => 1
|
||||||
}
|
}
|
||||||
}, actual)
|
}, actual)
|
||||||
end
|
end
|
||||||
@ -1099,7 +1101,8 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
:name => 'logo.png',
|
:name => 'logo.png',
|
||||||
:url => 'http://example.com/logo.png',
|
:url => 'http://example.com/logo.png',
|
||||||
:attachable => {
|
:attachable => {
|
||||||
:email => 1
|
:type => :email,
|
||||||
|
:id => 1
|
||||||
}},
|
}},
|
||||||
:emails => [{
|
:emails => [{
|
||||||
:id => 1,
|
:id => 1,
|
||||||
@ -1179,15 +1182,15 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
:oranges => [{
|
:oranges => [{
|
||||||
:plu => "3027",
|
:plu => "3027",
|
||||||
:id => 1,
|
:id => 1,
|
||||||
:readable => { :email => 1 }
|
:readable => { :type => :email, :id => 1 }
|
||||||
}],
|
}],
|
||||||
|
|
||||||
:attachment => {
|
:attachment => {
|
||||||
:name => 'logo.png',
|
:name => 'logo.png',
|
||||||
:url => 'http://example.com/logo.png',
|
:url => 'http://example.com/logo.png',
|
||||||
:attachable => { :email => 1 },
|
:attachable => { :type => :email, :id => 1 },
|
||||||
:readable => { :email => 1 },
|
:readable => { :type => :email, :id => 1 },
|
||||||
:edible => { :orange => 1 }
|
:edible => { :type => :orange, :id => 1 }
|
||||||
}
|
}
|
||||||
}, actual)
|
}, actual)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user