mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Separate associations into multiple files
This commit is contained in:
22
lib/active_model/serializer/association/has_one.rb
Normal file
22
lib/active_model/serializer/association/has_one.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Association
|
||||
class HasOne < Association
|
||||
def initialize(name, *args)
|
||||
super
|
||||
@root_key = @embedded_key.to_s.pluralize
|
||||
@key ||= "#{name}_id"
|
||||
end
|
||||
|
||||
def serializer_class(object)
|
||||
serializer_from_options || serializer_from_object(object) || default_serializer
|
||||
end
|
||||
|
||||
def build_serializer(object, options = {})
|
||||
options[:_wrap_in_array] = embed_in_root?
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user