From 9a958a3d7dc1640c90abbe1164d7ccb7ea9ae685 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 7 Oct 2009 12:43:04 -0300 Subject: Relations: Added offset when finding with associations. Delegate array instance methods to to_a. --- activerecord/lib/active_record/relation.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3