Permalink
Browse files

Use :foreign_key option if specified on the association

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1096 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent a5cffb3 commit 81014da84c9ae4dacb70287ff6f509d7a40cc0ae @dhh dhh committed Apr 5, 2005
Showing with 2 additions and 2 deletions.
  1. +2 −2 activerecord/lib/active_record/associations.rb
@@ -655,10 +655,10 @@ def construct_finder_sql_with_included_associations(options, reflections)
case reflection.macro
when :has_many, :has_one
sql << " LEFT JOIN #{reflection.klass.table_name} ON " +
- "#{reflection.klass.table_name}.#{table_name.classify.foreign_key} = #{table_name}.#{primary_key} "
+ "#{reflection.klass.table_name}.#{reflection.options[:foreign_key] || table_name.classify.foreign_key} = #{table_name}.#{primary_key} "
when :belongs_to
sql << " LEFT JOIN #{reflection.klass.table_name} ON " +
- "#{reflection.klass.table_name}.#{reflection.klass.primary_key} = #{table_name}.#{reflection.klass.table_name.classify.foreign_key} "
+ "#{reflection.klass.table_name}.#{reflection.klass.primary_key} = #{table_name}.#{reflection.options[:foreign_key] || reflection.klass.table_name.classify.foreign_key} "
end
end

0 comments on commit 81014da

Please sign in to comment.