Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord::Base.construct_finder_sql gives scope[:from] precedence over options[:from]

#1370

In activerecord/lib/active_record/base.rb


module ActiveRecord
  ...
  class Base
    ...
    class << self
      ...
      def construct_finder_sql(options)
        ...
        sql  = "SELECT #{options[:select] || (scope && scope[:select]) || ((options[:joins] || (scope && scope[:joins])) && quoted_table_name + '.*') || '*'} "
        sql << "FROM #{(scope && scope[:from]) || options[:from] || quoted_table_name} "
        ...

construct_finder_sql gives precedence to the options hash over the scope for query construction except for the "FROM" clause. This disallows "FROM" overriding when manually calling construct_finder_sql.

I propose that


sql << "FROM #{(scope && scope[:from]) || options[:from] || quoted_table_name} "

be changed to:


sql << "FROM #{options[:from] || (scope && scope[:from]) || quoted_table_name} "

Reported by John Wulff · November 13th, 2008 @ 10:08 PM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. John Wulff
  2. DHH
    DHH
    • Tag changed from activerecord to activerecord, patch

    Looks good to me, but we should have a test that verifies this behavior (one that fails before this patch and passes after).

    November 16th, 2008 @ 02:52 PM

  3. Repository
    Repository
    • State changed from new to resolved

    (from [4863634a157a8e4a0033734617253b42325daf34]) Ensure supplie :from has precedence over scoped :from [#1370 ActiveRecord::Base.construct_finder_sql gives scope[:from] precedence over op... state:resolved] http://github.com/rails/rails/co...

    March 6th, 2009 @ 06:38 PM