Module: ActiveRecord::FinderMethods

Defined in:
lib/active_record/connection_adapters/simpledb_adapter/finder_methods.rb

Instance Method Summary collapse

Instance Method Details

#exists?(id = nil) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_record/connection_adapters/simpledb_adapter/finder_methods.rb', line 3

def exists?(id = nil)
  id = id.id if ActiveRecord::Base === id

  join_dependency = construct_join_dependency_for_association_find
  relation = construct_relation_for_association_find(join_dependency)
  relation = relation.except(:select).select("*").limit(1)

  case id
  when Array, Hash
    relation = relation.where(id)
  else
    relation = relation.where(table[primary_key.name].eq(id)) if id
  end

  connection.select_value(relation.to_sql) ? true : false
end