diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-03 08:21:22 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-03 08:21:22 +0000 |
commit | d9d22c7596118051ba8908c163c797b90cca7aa3 (patch) | |
tree | e6cab8dca303f6479aac8e1d6fe5fa010df7a5ed /activerecord/lib/active_record/associations.rb | |
parent | 703d18ea520c3def7bc677cef5fd87e2c7c3cd34 (diff) | |
download | rails-d9d22c7596118051ba8908c163c797b90cca7aa3.tar.gz rails-d9d22c7596118051ba8908c163c797b90cca7aa3.tar.bz2 rails-d9d22c7596118051ba8908c163c797b90cca7aa3.zip |
Fixed that single-table inheritance sub-classes couldn't be used to limit the result set with eager loading #1215 [Chris McGrath]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1619 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index d82d58b94c..05d8bd9ad0 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -793,11 +793,21 @@ module ActiveRecord sql << reflections.collect { |reflection| association_join(reflection) }.to_s sql << "#{options[:joins]} " if options[:joins] add_conditions!(sql, options[:conditions]) + add_sti_conditions!(sql, reflections) sql << "ORDER BY #{options[:order]} " if options[:order] return sanitize_sql(sql) end + def add_sti_conditions!(sql, reflections) + sti_sql = "" + reflections.each do |reflection| + sti_sql << " AND #{reflection.klass.send(:type_condition)}" unless reflection.klass.descends_from_active_record? + end + sti_sql.sub!(/AND/, "WHERE") unless sql =~ /where/i + sql << sti_sql + end + def column_aliases(schema_abbreviations) schema_abbreviations.collect { |cn, tc| "#{tc.join(".")} AS #{cn}" }.join(", ") end |