aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2014-08-24 13:22:47 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2014-08-24 13:22:47 -0300
commitfe21a9fa7bff4f59f1814c72f3317e61f0ab3b60 (patch)
tree6d92dce15c7bbdc50bd5411cdbccb9159f530727 /activerecord
parentda3d8474221f6652983ac8460da635b89990c923 (diff)
parenta5ae5fc85161c26741e64273fd1620a7a8f4d296 (diff)
downloadrails-fe21a9fa7bff4f59f1814c72f3317e61f0ab3b60.tar.gz
rails-fe21a9fa7bff4f59f1814c72f3317e61f0ab3b60.tar.bz2
rails-fe21a9fa7bff4f59f1814c72f3317e61f0ab3b60.zip
Merge pull request #16675 from tomkadwill/has_many_documenting_extension_param
[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