aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2011-03-23 21:52:53 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-24 09:55:51 -0700
commit5214e73850916de3c9127d35a4ecee0424d364a3 (patch)
tree74fa9ff9524a51701cfa23f708b3f777c65b7fe5 /activerecord/lib/active_record/relation/finder_methods.rb
parent9772de8d459960cc114c5b214343b7ce08fea21c (diff)
downloadrails-5214e73850916de3c9127d35a4ecee0424d364a3.tar.gz
rails-5214e73850916de3c9127d35a4ecee0424d364a3.tar.bz2
rails-5214e73850916de3c9127d35a4ecee0424d364a3.zip
add #first! and #last! to models & relations
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb10
1 files changed, 10 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..25e23a9d55 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -123,6 +123,11 @@ module ActiveRecord
end
end
+ # Same as #first! but raises RecordNotFound if no record is returned
+ def first!(*args)
+ self.first(*args) 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 +142,11 @@ module ActiveRecord
end
end
+ # Same as #last! but raises RecordNotFound if no record is returned
+ def last!(*args)
+ self.last(*args) 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)