Skip to content

Commit

Permalink
Ensure supplie :from has precedence over scoped :from [#1370 state:re…
Browse files Browse the repository at this point in the history
…solved]
  • Loading branch information
lifo committed Mar 6, 2009
1 parent c896d56 commit 4863634
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -1690,7 +1690,7 @@ def default_select(qualified)
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)
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/finder_test.rb
Expand Up @@ -1057,6 +1057,14 @@ def test_with_limiting_with_custom_select
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)
Expand Down

2 comments on commit 4863634

@jwulff
Copy link

@jwulff jwulff commented on 4863634 Mar 6, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, thanks for committing.

http://rails.lighthouseapp.com/projects/8994/tickets/1370-activerecordbaseconstruct_finder_sql-gives-scopefrom-precedence-over-optionsfrom

@jwulff
Copy link

@jwulff jwulff commented on 4863634 Mar 6, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really glad to see this make it in, thanks!

http://rails.lighthouseapp.com/projects/8994/tickets/1370-activerecordbaseconstruct_finder_sql-gives-scopefrom-precedence-over-optionsfrom

Please sign in to comment.