diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2012-03-12 15:02:18 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-03-12 15:02:18 +0000 |
commit | ca99beb4a9fc983603e2427255afa97c63cc4cfc (patch) | |
tree | 95ad11daa05cdafd7f11d649ca6f0a3324790ce5 /railties/guides/source/active_record_querying.textile | |
parent | eee32af45e7909c02370324833d7117fe9b6eb37 (diff) | |
download | rails-ca99beb4a9fc983603e2427255afa97c63cc4cfc.tar.gz rails-ca99beb4a9fc983603e2427255afa97c63cc4cfc.tar.bz2 rails-ca99beb4a9fc983603e2427255afa97c63cc4cfc.zip |
Add documentation for find_or_create_by_{attribute}! method.
Diffstat (limited to 'railties/guides/source/active_record_querying.textile')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 2 |
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 d9a62f7574..8e23a577e2 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -1133,6 +1133,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': |