This project is archived and is in readonly mode.

#1370 ✓resolved
John Wulff

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

Reported by John Wulff | November 13th, 2008 @ 10:08 PM | in 2.x

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} "

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages