mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
As shown here : https://github.com/json-api/json-api/blob/gh-pages/format/index.md#resource-relationships-
25 lines
672 B
Ruby
25 lines
672 B
Ruby
module ActiveModel
|
|
class Serializer
|
|
class Association
|
|
class HasOne < Association
|
|
def initialize(name, *args)
|
|
super
|
|
@root_key = @embedded_key.to_s.pluralize
|
|
@key ||= case CONFIG.default_key_type
|
|
when :name then name.to_s.singularize
|
|
else "#{name}_id"
|
|
end
|
|
end
|
|
|
|
def serializer_class(object, options = {})
|
|
serializer_from_options || serializer_from_object(object, options) || default_serializer
|
|
end
|
|
|
|
def build_serializer(object, options = {})
|
|
options[:_wrap_in_array] = embed_in_root?
|
|
super
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end |