From 64d3b5edd11f5d96d4ac3393247d04c9e225878f Mon Sep 17 00:00:00 2001 From: Tom Kadwill Date: Tue, 26 Aug 2014 07:49:37 +0100 Subject: [ci skip] Added documentation for has_and_belongs_to_many extension parameter --- activerecord/lib/active_record/associations.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 18d4291599..18da28d480 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1604,6 +1604,21 @@ module ActiveRecord # where("default_category = ?", category.name) # } # + # === Extensions + # + # The +extension+ argument allows you to pass a block into a + # has_and_belongs_to_many association. This is useful for adding new + # finders, creators and other factory-type methods to be used as part of + # the association. + # + # Extension examples: + # has_and_belongs_to_many :contractors do + # def find_or_create_by_name(name) + # first_name, last_name = name.split(" ", 2) + # find_or_create_by(first_name: first_name, last_name: last_name) + # end + # end + # # === Options # # [:class_name] -- cgit v1.2.3