Skip to content

Commit

Permalink
Getting root key from AR::Relation
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomdmoura committed Jun 16, 2015
1 parent 65e0d79 commit e321cb3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/active_model/serializer/array_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class ArraySerializer
attr_reader :meta, :meta_key

def initialize(objects, options = {})
@objects = objects.map do |object|
@resource = objects
@objects = objects.map do |object|
serializer_class = options.fetch(
:serializer,
ActiveModel::Serializer.serializer_for(object)
Expand All @@ -19,7 +20,11 @@ def initialize(objects, options = {})
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)
Expand Down

0 comments on commit e321cb3

Please sign in to comment.