aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorTom Kadwill <tomkadwill@gmail.com>2014-08-24 17:03:57 +0100
committerTom Kadwill <tomkadwill@gmail.com>2014-08-24 17:03:57 +0100
commita5ae5fc85161c26741e64273fd1620a7a8f4d296 (patch)
tree8e42b1783785dfa79d1eaac576d5e1196102f5e6 /activerecord
parent525cbd4c2f1257f131e38caaecf01c7674b1130a (diff)
downloadrails-a5ae5fc85161c26741e64273fd1620a7a8f4d296.tar.gz
rails-a5ae5fc85161c26741e64273fd1620a7a8f4d296.tar.bz2
rails-a5ae5fc85161c26741e64273fd1620a7a8f4d296.zip
[ci skip] Added documentation for has_many extension parameter
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 4ec1c8d545..54390e612f 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1146,6 +1146,20 @@ module ActiveRecord
# has_many :employees, -> { joins(:address) }
# has_many :posts, ->(post) { where("max_post_length > ?", post.length) }
#
+ # === Extensions
+ #
+ # The +extension+ argument allows you to pass a block into a has_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_many :employees 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]
# Specify the class name of the association. Use it only if that name can't be inferred