aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2011-03-27 00:21:25 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2011-03-27 00:21:25 +0530
commit2fc32636dc07cd4986e065be2ab3fbded34cbe18 (patch)
tree7ceb3541e30d5559b0f51093f27970485d505f7e /activerecord/lib/active_record/relation/finder_methods.rb
parent547407a9fb375601deb0834fb1c2d9a108c9aea1 (diff)
parent7c6807296b114f0688e6e74494f1d43d3a0548ba (diff)
downloadrails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.tar.gz
rails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.tar.bz2
rails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 426000fde1..563843f3cc 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -123,6 +123,12 @@ module ActiveRecord
end
end
+ # Same as +first+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
+ # is found. Note that <tt>first!</tt> accepts no arguments.
+ def first!
+ first or raise RecordNotFound
+ end
+
# A convenience wrapper for <tt>find(:last, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:last)</tt>.
def last(*args)
@@ -137,6 +143,12 @@ module ActiveRecord
end
end
+ # Same as +last+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
+ # is found. Note that <tt>last!</tt> accepts no arguments.
+ def last!
+ last or raise RecordNotFound
+ end
+
# A convenience wrapper for <tt>find(:all, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:all)</tt>.
def all(*args)