diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 16 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 20 |
2 files changed, 18 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 3efcff11ca..be26b1f47f 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -142,22 +142,6 @@ module ActiveRecord relation.merge(scope) end - def first(*args) - if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) - to_a.first(*args) - else - args.first.present? ? apply_finder_options(args.first).first : super - end - end - - def last(*args) - if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) - to_a.last(*args) - else - args.first.present? ? apply_finder_options(args.first).last : super - end - end - def ==(other) case other when Scope diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 37aaac0894..a26f1c0ac8 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -106,13 +106,29 @@ module ActiveRecord # A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the # same arguments to this method as you can to <tt>find(:first)</tt>. def first(*args) - args.any? ? apply_finder_options(args.first).first : find_first + if args.any? + if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) + to_a.first(*args) + else + apply_finder_options(args.first).first + end + else + find_first + end 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) - args.any? ? apply_finder_options(args.first).last : find_last + if args.any? + if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) + to_a.last(*args) + else + apply_finder_options(args.first).last + end + else + find_last + end end # A convenience wrapper for <tt>find(:all, *args)</tt>. You can pass in all the |