aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-11-29 18:58:41 +0000
committerJon Leighton <j@jonathanleighton.com>2011-11-29 20:13:37 +0000
commit1a474cc8e41522ae079871d297c0e61ee4f6ef35 (patch)
tree23d2b2c2c74dc02f68ad6015bf35ce554096cdde /activerecord/lib/active_record/attribute_methods
parent4aad289428bf46cf4a13f159819f1993f8fc978f (diff)
downloadrails-1a474cc8e41522ae079871d297c0e61ee4f6ef35.tar.gz
rails-1a474cc8e41522ae079871d297c0e61ee4f6ef35.tar.bz2
rails-1a474cc8e41522ae079871d297c0e61ee4f6ef35.zip
Deprecate set_primary_key in favour of self.primary_key=
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb46
1 files changed, 26 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index a404a5edd7..93dae3ff86 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -22,11 +22,11 @@ module ActiveRecord
end
def reset_primary_key #:nodoc:
- key = self == base_class ? get_primary_key(base_class.name) :
- base_class.primary_key
-
- set_primary_key(key)
- key
+ if self == base_class
+ self.primary_key = get_primary_key(base_class.name)
+ else
+ self.primary_key = base_class.primary_key
+ end
end
def get_primary_key(base_name) #:nodoc:
@@ -46,27 +46,33 @@ module ActiveRecord
end
end
- attr_accessor :original_primary_key
-
- # Attribute writer for the primary key column
- def primary_key=(value)
- @quoted_primary_key = nil
- @primary_key = value
+ def original_primary_key #:nodoc:
+ deprecated_original_property_getter :primary_key
end
- # Sets the name of the primary key column to use to the given value,
- # or (if the value is nil or false) to the value returned by the given
- # block.
+ # Sets the name of the primary key column.
#
# class Project < ActiveRecord::Base
- # set_primary_key "sysid"
+ # self.primary_key = "sysid"
# end
- def set_primary_key(value = nil, &block)
+ #
+ # You can also define the primary_key method yourself:
+ #
+ # class Project < ActiveRecord::Base
+ # def self.primary_key
+ # "foo_" + super
+ # end
+ # end
+ # Project.primary_key # => "foo_id"
+ def primary_key=(value)
+ @original_primary_key = @primary_key if defined?(@primary_key)
+ @primary_key = value && value.to_s
+ @quoted_primary_key = nil
+ end
+
+ def set_primary_key(value = nil, &block) #:nodoc:
+ deprecated_property_setter :primary_key, value, block
@quoted_primary_key = nil
- @primary_key ||= ''
- self.original_primary_key = @primary_key
- value &&= value.to_s
- self.primary_key = block_given? ? instance_eval(&block) : value
end
end
end