Skip to content

Commit

Permalink
Merge pull request #28372 from kamipo/delegate_as_json
Browse files Browse the repository at this point in the history
Simply delegate `as_json` to `records`
  • Loading branch information
pixeltrix committed Mar 12, 2017
2 parents 21a4491 + 4368dba commit fa9b4c4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 6 deletions.
4 changes: 0 additions & 4 deletions activerecord/lib/active_record/relation.rb
Expand Up @@ -261,10 +261,6 @@ def encode_with(coder)
coder.represent_seq(nil, records)
end

def as_json(options = nil) #:nodoc:
records.as_json(options)
end

# Returns size of the records.
def size
loaded? ? @records.length : count(:all)
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/delegation.rb
Expand Up @@ -38,7 +38,7 @@ def inherited(child_class)

delegate :to_xml, :encode_with, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join,
:[], :&, :|, :+, :-, :sample, :reverse, :compact, :in_groups, :in_groups_of,
:to_sentence, :to_formatted_s,
:to_sentence, :to_formatted_s, :as_json,
:shuffle, :split, :index, to: :records

delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key,
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/relation/delegation_test.rb
Expand Up @@ -33,7 +33,7 @@ module DelegationWhitelistBlacklistTests
:map, :none?, :one?, :partition, :reject, :reverse,
:sample, :second, :sort, :sort_by, :third,
:to_ary, :to_set, :to_xml, :to_yaml, :join,
:in_groups, :in_groups_of, :to_sentence, :to_formatted_s
:in_groups, :in_groups_of, :to_sentence, :to_formatted_s, :as_json
]

ARRAY_DELEGATES.each do |method|
Expand Down

0 comments on commit fa9b4c4

Please sign in to comment.