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

      join_dependency = construct_join_dependency_for_association_find
      relation = construct_relation_for_association_find(join_dependency)
      relation = relation.except(:select, :order).select("1 AS one").limit(1)

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

      connection.select_value(relation, "#{name} Exists") ? true : false
    rescue ThrowResult
      false
    end
def exists?(id = false)
      id = id.id if ActiveRecord::Base === id
      return false if id.nil?

      join_dependency = construct_join_dependency_for_association_find
      relation = construct_relation_for_association_find(join_dependency)
      relation = relation.except(:select, :order).select("1 AS one").limit(1)

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

      connection.select_value(relation, "#{name} Exists") ? true : false
    rescue ThrowResult
      false
    end
Returns true if a record exists in the table that matches the +id+ or
 conditions given, or false otherwise. The argument can take five forms:

 * Integer - Finds the record with this primary key.
 * String - Finds the record with a primary key corresponding to this
   string (such as <tt>'5'</tt>).
 * Array - Finds the record that matches these +find+-style conditions
   (such as <tt>['color = ?', 'red']</tt>).
 * Hash - Finds the record that matches these +find+-style conditions
   (such as <tt>{:color => 'red'}</tt>).
 * No args - Returns false if the table is empty, true otherwise.

 For more information about specifying conditions as a Hash or Array,
 see the Conditions section in the introduction to ActiveRecord::Base.

 Note: You can't pass in a condition as a string (like <tt>name =
 'Jamie'</tt>), since it would be sanitized and then queried against
 the primary key column, like <tt>id = 'name = \'Jamie\''</tt>.

 ==== Examples
   Person.exists?(5)
   Person.exists?('5')
   Person.exists?(:name => "David")
   Person.exists?(['name LIKE ?', "%#{query}%"])
   Person.exists?