From 4863634a157a8e4a0033734617253b42325daf34 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 6 Mar 2009 18:36:30 +0000 Subject: [PATCH] Ensure supplie :from has precedence over scoped :from [#1370 state:resolved] --- activerecord/lib/active_record/base.rb | 2 +- activerecord/test/cases/finder_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 206b4efa38..ea791b5bfe 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1690,7 +1690,7 @@ module ActiveRecord #:nodoc: def construct_finder_sql(options) scope = scope(:find) sql = "SELECT #{options[:select] || (scope && scope[:select]) || default_select(options[:joins] || (scope && scope[:joins]))} " - sql << "FROM #{(scope && scope[:from]) || options[:from] || quoted_table_name} " + sql << "FROM #{options[:from] || (scope && scope[:from]) || quoted_table_name} " add_joins!(sql, options[:joins], scope) add_conditions!(sql, options[:conditions], scope) diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index ee8f4901f9..9d444a92ae 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -1057,6 +1057,14 @@ class FinderTest < ActiveRecord::TestCase assert_equal [0, 1, 1], posts.map(&:author_id).sort end + def test_finder_with_scoped_from + all_topics = Topic.all + + Topic.with_scope(:find => { :from => 'fake_topics' }) do + assert_equal all_topics, Topic.all(:from => 'topics') + end + end + protected def bind(statement, *vars) if vars.first.is_a?(Hash)