From f8eb4434d61fc1585c9b88dbb2d9159ea1f5b2fa Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 3 Aug 2009 14:15:47 -0300 Subject: Added collection iteration to AR::Relation. --- activerecord/lib/active_record/relation.rb | 4 ++++ activerecord/test/cases/relations_test.rb | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 1c3a1dc53b..f89baa1a74 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -13,6 +13,10 @@ module ActiveRecord @klass.find_by_sql(@relation.to_sql) end + def each(&block) + to_a.each(&block) + end + def first @relation = @relation.take(1) to_a.first diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index c095d9455e..ac3a80afb7 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -73,6 +73,5 @@ class RealtionTest < ActiveRecord::TestCase ).to_a assert_equal 1, person_with_reader_and_post.size end - end -- cgit v1.2.3