From b94d4fa059c8f30a09cc6db4faf40a081760bc21 Mon Sep 17 00:00:00 2001 From: Lawrence Pit Date: Thu, 10 Jun 2010 21:25:19 +1000 Subject: [PATCH] ActiveRecord::Relation to_json / to_yaml --- activerecord/lib/active_record/relation.rb | 2 +- activerecord/test/cases/relations_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 99c914d..a6beec4 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -9,7 +9,7 @@ module ActiveRecord include FinderMethods, Calculations, SpawnMethods, QueryMethods, Batches - delegate :length, :collect, :map, :each, :all?, :include?, :to => :to_a + delegate :length, :collect, :map, :each, :all?, :include?, :to_json, :to_yaml, :to => :to_a delegate :insert, :to => :arel attr_reader :table, :klass diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 43519db..c9fc8f1 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -593,4 +593,10 @@ class RelationTest < ActiveRecord::TestCase assert_equal "lifo", relation.author assert_equal "lifo", relation.limit(1).author end + + def test_delegation_to_yaml_and_to_json + relation = Post.where(:author_id => 1) + assert_equal relation.to_a.to_yaml, relation.to_yaml + assert_equal relation.to_a.to_json, relation.to_json + end end -- 1.7.0