aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2012-03-12 15:02:18 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2012-03-12 15:03:04 +0000
commita01f0ab83981f0ea15a1f683b84186961732f416 (patch)
treee9c980c0a4327e871e7b9eb9b65e3c9c5db5c361 /railties/guides
parent90d96353e6dcd962b182e03f53f2214acde00907 (diff)
downloadrails-a01f0ab83981f0ea15a1f683b84186961732f416.tar.gz
rails-a01f0ab83981f0ea15a1f683b84186961732f416.tar.bz2
rails-a01f0ab83981f0ea15a1f683b84186961732f416.zip
Add documentation for find_or_create_by_{attribute}! method.
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/active_record_querying.textile2
1 files changed, 2 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index d9d7d38db5..47392c1851 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -1109,6 +1109,8 @@ Client.where(:first_name => 'Andy').first_or_create!(:locked => false)
# => ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank
</ruby>
+As with +first_or_create+ there is a +find_or_create_by!+ method but the +first_or_create!+ method is preferred for clarity.
+
h4. +first_or_initialize+
The +first_or_initialize+ method will work just like +first_or_create+ but it will not call +create+ but +new+. This means that a new model instance will be created in memory but won't be saved to the database. Continuing with the +first_or_create+ example, we now want the client named 'Nick':