Skip to content

Commit

Permalink
document the change in edge rails which makes a more strict check on …
Browse files Browse the repository at this point in the history
…the arity of the dynamic finders
  • Loading branch information
vijaydev committed Jul 22, 2011
1 parent ccb3af4 commit 573c6e6
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions railties/guides/source/active_record_querying.textile
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ You can specify an exclamation point (<tt>!</tt>) on the end of the dynamic find

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)+.

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+.

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")+:

Expand Down

0 comments on commit 573c6e6

Please sign in to comment.