diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-08-31 15:06:02 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-08-31 15:06:02 -0300 |
commit | 87e50f104a27b6c6d1452839adef7c7350769071 (patch) | |
tree | 62a5915bf46f9f0b03598471670c5eeacf345146 /activerecord/lib/active_record/relation/query_methods.rb | |
parent | 2431af1b7f731067cd01223b5e0fab3dc55ebea6 (diff) | |
download | rails-87e50f104a27b6c6d1452839adef7c7350769071.tar.gz rails-87e50f104a27b6c6d1452839adef7c7350769071.tar.bz2 rails-87e50f104a27b6c6d1452839adef7c7350769071.zip |
Improved conditionals usage to prevent calling methods.
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index de7e5c7131..5549358fcd 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -43,20 +43,31 @@ module ActiveRecord end def joins(*args) - args.flatten! - args.present? ? clone.tap {|r| r.joins_values += args } : clone + if args.present? + args.flatten! + clone.tap {|r| r.joins_values += args } + else + clone + end end def where(opts, *rest) - value = build_where(opts, rest) - copy = clone - copy.where_values += Array.wrap(value) if value - copy + if value = build_where(opts, rest) + copy = clone + copy.where_values += Array.wrap(value) + copy + else + clone + end end def having(*args) - value = build_where(*args) - value.present? ? clone.tap {|r| r.having_values += Array.wrap(value) } : clone + if args.present? + value = build_where(*args) + clone.tap {|r| r.having_values += Array.wrap(value) } + else + clone + end end def limit(value = true) |