Browse files

exists? method now uses ARel

  • Loading branch information...
1 parent 5b61168 commit ca0530a53f6b019b0f5eb9a8c5c8b0081cd20d12 @miloops miloops committed Apr 30, 2009
Showing with 5 additions and 10 deletions.
  1. +5 −10 activerecord/lib/active_record/base.rb
View
15 activerecord/lib/active_record/base.rb
@@ -688,14 +688,9 @@ def find_by_sql(sql)
# Person.exists?(['name LIKE ?', "%#{query}%"])
# Person.exists?
def exists?(id_or_conditions = {})
- connection.select_all(
- construct_finder_sql(
- :select => "#{quoted_table_name}.#{primary_key}",
- :conditions => expand_id_conditions(id_or_conditions),
- :limit => 1
- ),
- "#{name} Exists"
- ).size > 0
+ construct_finder_arel({
+ :conditions =>expand_id_conditions(id_or_conditions)
+ }).project(arel_table[primary_key]).take(1).count > 0
end
# Creates an object (or multiple objects) and saves it to the database, if validations pass.
@@ -1685,8 +1680,8 @@ def default_select(qualified)
end
end
- def arel_table(table)
- Arel(table)
+ def arel_table(table = table_name)
+ @arel_table = Arel(table)
end
def construct_finder_arel(options)

1 comment on commit ca0530a

@smtlaissezfaire

What's the general advantage of using Arel? Structured queries?

Please sign in to comment.