mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure supplie :from has precedence over scoped :from [#1370 state:resolved]
This commit is contained in:
parent
c896d56c6e
commit
4863634a15
2 changed files with 9 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue