mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Getting root key from AR::Relation
This commit is contained in:
parent
65e0d79195
commit
e321cb366d
@ -7,6 +7,7 @@ module ActiveModel
|
||||
attr_reader :meta, :meta_key
|
||||
|
||||
def initialize(objects, options = {})
|
||||
@resource = objects
|
||||
@objects = objects.map do |object|
|
||||
serializer_class = options.fetch(
|
||||
:serializer,
|
||||
@ -19,7 +20,11 @@ module ActiveModel
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def root=(root)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user