aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2005-12-16 23:24:58 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2005-12-16 23:24:58 +0000
commit5f06c483ca6a0434409aa12ec272654bc26735dd (patch)
tree4d4e05b12d3aa659550e972f65ae5e2712869ff8 /activerecord/lib
parent85fe1ecaefe415ac1de36883f5f6162f49bd5287 (diff)
downloadrails-5f06c483ca6a0434409aa12ec272654bc26735dd.tar.gz
rails-5f06c483ca6a0434409aa12ec272654bc26735dd.tar.bz2
rails-5f06c483ca6a0434409aa12ec272654bc26735dd.zip
Fixed :through relations when using STI inherited classes would use the inherited class's name as foreign key on the join model
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3315 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index f6ac03a3e6..8c91aeeed4 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -51,6 +51,7 @@ module ActiveRecord
def construct_conditions
through_reflection = @owner.class.reflections[@reflection.options[:through]]
+ through_foreign_classname = ActiveRecord::Base.send(:class_name_of_active_record_descendant, @owner.class).to_s
if through_reflection.options[:as]
conditions =
@@ -60,7 +61,7 @@ module ActiveRecord
else
conditions =
"#{@reflection.klass.table_name}.#{@reflection.klass.primary_key} = #{through_reflection.table_name}.#{@reflection.klass.to_s.foreign_key} " +
- "AND #{through_reflection.table_name}.#{@owner.class.to_s.foreign_key} = #{@owner.quoted_id}"
+ "AND #{through_reflection.table_name}.#{through_foreign_classname.foreign_key} = #{@owner.quoted_id}"
end
conditions << " AND (#{interpolate_sql(sanitize_sql(@reflection.options[:conditions]))})" if @reflection.options[:conditions]