提交 9a958a3d 编写于 作者: E Emilio Tagua

Relations: Added offset when finding with associations. Delegate array instance

methods to to_a.
上级 aadb09b1
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 @@ def to_a
: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 @@ def to_a
records
end
def each(&block)
to_a.each(&block)
end
def first
@relation = @relation.take(1)
to_a.first
......
......@@ -122,12 +122,12 @@ def test_default_scope_with_conditions_string
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 @@ def test_loading_with_one_association
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册