diff options
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 32e812a86a..e54e38e184 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -118,10 +118,11 @@ module ActiveRecord def primary_key_name return @primary_key_name if @primary_key_name - - case macro - when :belongs_to + case + when macro == :belongs_to @primary_key_name = options[:foreign_key] || class_name.foreign_key + when options[:as] + @primary_key_name = options[:foreign_key] || "#{options[:as]}_id" else @primary_key_name = options[:foreign_key] || active_record.name.foreign_key end |