aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/relation.rb8
-rw-r--r--activerecord/test/cases/relations_test.rb9
2 files changed, 7 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index db1c9c24de..6bc56ecf15 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -1,6 +1,7 @@
module ActiveRecord
class Relation
delegate :to_sql, :to => :relation
+ delegate :length, :collect, :find, :map, :each, :to => :to_a
attr_reader :relation, :klass
def initialize(klass, relation)
@@ -34,7 +35,8 @@ module ActiveRecord
:group => @relation.send(:group_clauses).join(', '),
:order => @relation.send(:order_clauses).join(', '),
:conditions => @relation.send(:where_clauses).join("\n\tAND "),
- :limit => @relation.taken
+ :limit => @relation.taken,
+ :offset => @relation.skipped
},
ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, @eager_load_associations, nil))
end
@@ -49,10 +51,6 @@ module ActiveRecord
records
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 54b72554b9..4833d04aff 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -122,12 +122,12 @@ class RelationTest < ActiveRecord::TestCase
end
def test_default_scope_with_conditions_hash
- assert_equal Developer.find_all_by_name('Jamis').map(&:id).sort, DeveloperCalledJamis.all.to_a.map(&:id).sort
+ assert_equal Developer.find_all_by_name('Jamis').map(&:id).sort, DeveloperCalledJamis.all.map(&:id).sort
assert_equal 'Jamis', DeveloperCalledJamis.create!.name
end
def test_loading_with_one_association
- posts = Post.all(:include => :comments).to_a
+ posts = Post.all(:include => :comments)
post = posts.find { |p| p.id == 1 }
assert_equal 2, post.comments.size
assert post.comments.include?(comments(:greetings))
@@ -136,16 +136,15 @@ class RelationTest < ActiveRecord::TestCase
assert_equal 2, post.comments.size
assert post.comments.include?(comments(:greetings))
- posts = Post.all(:include => :last_comment).to_a
+ posts = Post.all(:include => :last_comment)
post = posts.find { |p| p.id == 1 }
assert_equal Post.find(1).last_comment, post.last_comment
end
def test_loading_with_one_association_with_non_preload
- posts = Post.all(:include => :last_comment, :order => 'comments.id DESC').to_a
+ posts = Post.all(:include => :last_comment, :order => 'comments.id DESC')
post = posts.find { |p| p.id == 1 }
assert_equal Post.find(1).last_comment, post.last_comment
end
-
end