From 13ebf69ae4a47f2d1d2b1eebd1e84df2098e3a57 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 23 Aug 2010 05:45:11 -0400 Subject: unscoped does not work when chained with named_scope --- activerecord/lib/active_record/base.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 3be302a5fd..bbb44f0e17 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -876,6 +876,11 @@ module ActiveRecord #:nodoc: # limit(10) # Fires "SELECT * FROM posts LIMIT 10" # } # + # It is recommended to use block form of unscoped because chaining unscoped with named_scope + # does not work. Assuming that published is a named_scope following two statements are same. + # + # Post.unscoped.published + # Post.published def unscoped block_given? ? relation.scoping { yield } : relation end -- cgit v1.2.3 From f460de1d237e02fdbc3006bc91813efe7837f576 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 24 Aug 2010 10:21:58 -0400 Subject: touch operationg if used along with belongs_to will also be invoked on associated objects --- activerecord/lib/active_record/persistence.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 0188972169..c342824712 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -208,10 +208,14 @@ module ActiveRecord # If an attribute name is passed, that attribute is updated along with # updated_at/on attributes. # - # Examples: - # # product.touch # updates updated_at/on # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on + # + # If used along with +belongs_to+ then +touch+ will invoke +touch+ method on associated object. + # + # Brake.belongs_to :car, :touch => true + # Car.belongs_to :corporation, :touch => true + # @brake.touch #=> will also invoke @brake.car.touch and @brake.car.corporation.touch def touch(name = nil) attributes = timestamp_attributes_for_update_in_model attributes << name if name -- cgit v1.2.3