aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-12-28 03:56:20 +0530
committerPratik Naik <pratiknaik@gmail.com>2009-12-28 03:59:44 +0530
commit1c26ba486c23f229a12fea6ccad33e6cb3122b91 (patch)
tree87c964ab22dbeb1a517d293a5e4b7f696566d2db
parent6a776dcc9df437c0bcc3c1ff1d2a79966264bac9 (diff)
downloadrails-1c26ba486c23f229a12fea6ccad33e6cb3122b91.tar.gz
rails-1c26ba486c23f229a12fea6ccad33e6cb3122b91.tar.bz2
rails-1c26ba486c23f229a12fea6ccad33e6cb3122b91.zip
Add Model.from and association_collection#from finder methods
-rw-r--r--activerecord/CHANGELOG5
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb2
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rw-r--r--activerecord/test/cases/associations/eager_test.rb9
-rw-r--r--activerecord/test/cases/finder_test.rb2
5 files changed, 9 insertions, 11 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 4daeb6a302..3f4d77979b 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,10 @@
*Edge*
+* Add Model.from and association_collection#from finder methods [Pratik Naik]
+
+ user = User.scoped
+ user.select('*').from('users, items')
+
* Add relation.destroy_all [Pratik Naik]
old_items = Item.where("age > 100")
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index ac970f02b1..d2c61cdc78 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -21,7 +21,7 @@ module ActiveRecord
construct_sql
end
- delegate :group, :order, :limit, :joins, :where, :preload, :eager_load, :to => :scoped
+ delegate :group, :order, :limit, :joins, :where, :preload, :eager_load, :from, :to => :scoped
def select(select = nil, &block)
if block_given?
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index bbc5bd77c5..3b880ce17f 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -652,7 +652,7 @@ module ActiveRecord #:nodoc:
end
end
- delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :to => :scoped
+ delegate :select, :group, :order, :limit, :joins, :where, :preload, :eager_load, :from, :to => :scoped
# A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:first)</tt>.
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index d5a4d9007b..7fa5557b96 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -61,14 +61,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_with_two_tables_in_from_without_getting_double_quoted
- posts = Post.find(:all,
- :select => "posts.*",
- :from => "authors, posts",
- :include => :comments,
- :conditions => "posts.author_id = authors.id",
- :order => "posts.id"
- )
-
+ posts = Post.select("posts.*").from("authors, posts").eager_load(:comments).where("posts.author_id = authors.id").order("posts.id").to_a
assert_equal 2, posts.first.comments.size
end
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index c531a2dec1..87a9630978 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -1023,7 +1023,7 @@ class FinderTest < ActiveRecord::TestCase
all_topics = Topic.find(:all)
Topic.with_scope(:find => { :from => 'fake_topics' }) do
- assert_equal all_topics, Topic.all(:from => 'topics').to_a
+ assert_equal all_topics, Topic.from('topics').to_a
end
end