From 621eb3b666f2df84b7d40d5074eb033204d38146 Mon Sep 17 00:00:00 2001 From: Joost Baaij Date: Fri, 6 Jan 2012 11:53:01 +0100 Subject: Expanded rdoc about primary keys being protected from mass assignment. People need to make sure they are generated internally or added to attr_accessible so they can be mass assigned (for instance, from an import job). --- activerecord/lib/active_record/attribute_methods/primary_key.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb index a7785f8786..7c59664703 100644 --- a/activerecord/lib/active_record/attribute_methods/primary_key.rb +++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb @@ -44,7 +44,8 @@ module ActiveRecord end # Defines the primary key field -- can be overridden in subclasses. Overwriting will negate any effect of the - # primary_key_prefix_type setting, though. + # primary_key_prefix_type setting, though. Since primary keys are usually protected from mass assignment, + # remember to let your database generate them or include the key in +attr_accessible+. def primary_key @primary_key = reset_primary_key unless defined? @primary_key @primary_key -- cgit v1.2.3 From 23f8c635c0c8c9f6fbe810766104a4fa9f6794d4 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Mon, 9 Jan 2012 11:20:52 -0500 Subject: add documentation explaining reorder behavior --- activerecord/lib/active_record/relation/query_methods.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index c281bead0d..bfb5c27578 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -93,6 +93,16 @@ module ActiveRecord relation end + # Replaces any existing order defined on the relation with the specified order. + # + # User.order('email DESC').reorder('id ASC') # generated SQL has 'ORDER BY id ASC' + # + # Subsequent calls to order on the same relation will be appended. For example: + # + # User.order('email DESC').reorder('id ASC').order('name ASC') + # + # generates a query with 'ORDER BY id ASC, name ASC'. + # def reorder(*args) return self if args.blank? -- cgit v1.2.3