From 10834e975a54b63a07896cb8a6a16c336e20a792 Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Sun, 27 Nov 2011 14:12:46 -0800 Subject: changelog & docs for GeneratedFeatureMethods --- activerecord/lib/active_record/associations.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 34684ad2f5..60bbc325df 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -196,6 +196,26 @@ module ActiveRecord # * Project#categories.empty?, Project#categories.size, Project#categories, Project#categories<<(category1), # Project#categories.delete(category1) # + # === Overriding generated methods + # + # Association methods are generated in a module that is included into the model class, + # which allows you to easily override with your own methods and call the original + # generated method with +super+. For example: + # + # class Car < ActiveRecord::Base + # belongs_to :owner + # belongs_to :old_owner + # def owner=(new_owner) + # self.old_owner = self.owner + # super + # end + # end + # + # If your model class is Project, the module is + # named Project::GeneratedFeatureMethods. The GeneratedFeatureMethods module is + # is included in the model class immediately after the (anonymous) generated attributes methods + # module, meaning an association will override the methods for an attribute with the same name. + # # === A word of warning # # Don't create associations that have the same name as instance methods of -- cgit v1.2.3