diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-20 17:33:26 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-20 19:47:15 -0800 |
commit | 207f266ccaaa9cd04cd2a7513ae5598c4358b510 (patch) | |
tree | e197d33af7d701d183ed326f7d1c63b915b26fc7 /activerecord/lib/active_record | |
parent | 099a210c837daae692154add3b9da0a207825d35 (diff) | |
download | rails-207f266ccaaa9cd04cd2a7513ae5598c4358b510.tar.gz rails-207f266ccaaa9cd04cd2a7513ae5598c4358b510.tar.bz2 rails-207f266ccaaa9cd04cd2a7513ae5598c4358b510.zip |
define_attr_method must serialize nil correctly
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/primary_key.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb index 5ae1ebc9cf..c016e936cb 100644 --- a/activerecord/lib/active_record/attribute_methods/primary_key.rb +++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb @@ -24,7 +24,7 @@ module ActiveRecord end def get_primary_key(base_name) #:nodoc: - return unless base_name + return unless base_name && !base_name.blank? case primary_key_prefix_type when :table_name @@ -32,7 +32,11 @@ module ActiveRecord when :table_name_with_underscore base_name.foreign_key else - 'id' + if ActiveRecord::Base != self && connection.table_exists?(table_name) + connection.primary_key(table_name) + else + 'id' + end end end |