From 2524cf404ce943eca8a5f2d173188fd0cf2ac8b9 Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Sun, 29 Aug 2010 16:10:31 +0200 Subject: fixed some issues with JSON encoding - as_json in ActiveModel should return a hash and handle :only/:except/:methods options - Array and Hash should call as_json on their elements - json methods should not modify options argument [#5374 state:committed] Signed-off-by: Jeremy Kemper --- activerecord/lib/active_record/relation.rb | 4 +++- activerecord/lib/active_record/serialization.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index c678ef3bcc..478f1e8ef1 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -76,7 +76,9 @@ module ActiveRecord @records end - def as_json(options = nil) to_a end #:nodoc: + def as_json(options = nil) #:nodoc: + to_a.as_json(options) + end # Returns size of the records. def size diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb index 6ec406316a..ad3f7afd6f 100644 --- a/activerecord/lib/active_record/serialization.rb +++ b/activerecord/lib/active_record/serialization.rb @@ -5,7 +5,7 @@ module ActiveRecord #:nodoc: include ActiveModel::Serializers::JSON def serializable_hash(options = nil) - options ||= {} + options = options.try(:clone) || {} options[:except] = Array.wrap(options[:except]).map { |n| n.to_s } options[:except] |= Array.wrap(self.class.inheritance_column) -- cgit v1.2.3