Skip to content
This repository
Browse code

document the change in edge rails which makes a more strict check on …

…the arity of the dynamic finders
  • Loading branch information...
commit 573c6e6982224e6817174d2f9c288b6ddc938608 1 parent ccb3af4
Vijay Dev vijaydev authored

Showing 1 changed file with 1 addition and 0 deletions. Show diff stats Hide diff stats

  1. +1 0  railties/guides/source/active_record_querying.textile
1  railties/guides/source/active_record_querying.textile
Source Rendered
@@ -1016,6 +1016,7 @@ You can specify an exclamation point (<tt>!</tt>) on the end of the dynamic find
1016 1016
1017 1017 If you want to find both by name and locked, you can chain these finders together by simply typing +and+ between the fields. For example, +Client.find_by_first_name_and_locked("Ryan", true)+.
1018 1018
  1019 +WARNING: Up to and including Rails 3.1, when the number of arguments passed to a dynamic finder method is lesser than the number of fields, say <tt>Client.find_by_name_and_locked("Ryan")</tt>, the behavior is to pass +nil+ as the missing argument. This is *unintentional* and this behavior will be changed in Rails 3.2 to throw an +ArgumentError+.
1019 1020
1020 1021 There's another set of dynamic finders that let you find or create/initialize objects if they aren't found. These work in a similar fashion to the other finders and can be used like +find_or_create_by_first_name(params[:first_name])+. Using this will first perform a find and then create if the find returns +nil+. The SQL looks like this for +Client.find_or_create_by_first_name("Ryan")+:
1021 1022

0 comments on commit 573c6e6

Please sign in to comment.
Something went wrong with that request. Please try again.