resync from rails_port 11795:12304
[rails.git] / vendor / gems / composite_primary_keys-1.1.0 / lib / composite_primary_keys / reflection.rb
1 module ActiveRecord\r
2   module Reflection\r
3     class AssociationReflection\r
4       def primary_key_name\r
5         return @primary_key_name if @primary_key_name\r
6         case\r
7           when macro == :belongs_to\r
8             @primary_key_name = options[:foreign_key] || class_name.foreign_key\r
9           when options[:as]\r
10             @primary_key_name = options[:foreign_key] || "#{options[:as]}_id"\r
11           else\r
12             @primary_key_name = options[:foreign_key] || active_record.name.foreign_key\r
13         end\r
14         @primary_key_name = @primary_key_name.to_composite_keys.to_s if @primary_key_name.is_a? Array\r
15         @primary_key_name\r
16       end\r
17     end\r
18   end\r
19 end