diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-03 08:52:59 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-03 08:52:59 +0000 |
commit | df95128e9402feb1fc08b4ac45db73daa2edade3 (patch) | |
tree | c73ba67b0097bc9383b9454e016a78da506a7a7b /activerecord/lib | |
parent | 38e0862c816f45292ca1b78011588e1f56b95850 (diff) | |
download | rails-df95128e9402feb1fc08b4ac45db73daa2edade3.tar.gz rails-df95128e9402feb1fc08b4ac45db73daa2edade3.tar.bz2 rails-df95128e9402feb1fc08b4ac45db73daa2edade3.zip |
Fixed that has_and_belongs_to_many didn't respect single table inheritance types #1081 [Florian Weber]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1641 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index b34574161f..da43e32fb6 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -158,6 +158,15 @@ module ActiveRecord "j.#{@association_class_primary_key_name} = #{@owner.quoted_id} " @finder_sql << " AND #{interpolate_sql(@options[:conditions])}" if @options[:conditions] + + unless @association_class.descends_from_active_record? + type_condition = @association_class.send(:subclasses).inject("t.#{@association_class.inheritance_column} = '#{@association_class.name.demodulize}' ") do |condition, subclass| + condition << "OR t.#{@association_class.inheritance_column} = '#{subclass.name.demodulize}' " + end + + @finder_sql << " AND (#{type_condition})" + end + @finder_sql << " ORDER BY #{@order}" if @order end end |