mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Getting root key from AR::Relation
This commit is contained in:
parent
65e0d79195
commit
e321cb366d
@ -7,7 +7,8 @@ module ActiveModel
|
|||||||
attr_reader :meta, :meta_key
|
attr_reader :meta, :meta_key
|
||||||
|
|
||||||
def initialize(objects, options = {})
|
def initialize(objects, options = {})
|
||||||
@objects = objects.map do |object|
|
@resource = objects
|
||||||
|
@objects = objects.map do |object|
|
||||||
serializer_class = options.fetch(
|
serializer_class = options.fetch(
|
||||||
:serializer,
|
:serializer,
|
||||||
ActiveModel::Serializer.serializer_for(object)
|
ActiveModel::Serializer.serializer_for(object)
|
||||||
@ -19,7 +20,11 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def json_key
|
def json_key
|
||||||
@objects.first.json_key.pluralize if @objects.first
|
if @objects.first
|
||||||
|
@objects.first.json_key.pluralize
|
||||||
|
else
|
||||||
|
@resource.name.downcase.pluralize if @resource.try(:name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def root=(root)
|
def root=(root)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user