Skip to content

Commit

Permalink
Add Relation#all as an alias for to_a
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Dec 26, 2009
1 parent a73fa93 commit feb8b20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/relation.rb
Expand Up @@ -51,6 +51,8 @@ def to_a
records
end

alias all to_a

def first
@relation = @relation.take(1)
to_a.first
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -18,6 +18,12 @@ def test_scoped
assert_equal 4, topics.size
end

def test_scoped_all
topics = Topic.scoped.all
assert_kind_of Array, topics
assert_no_queries { assert_equal 4, topics.size }
end

def test_finding_with_conditions
assert_equal ["David"], Author.where(:name => 'David').map(&:name)
assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name)
Expand Down

0 comments on commit feb8b20

Please sign in to comment.