Module: Believer::FinderMethods

Included in:
Base, Relation::Collection
Defined in:
lib/believer/finder_methods.rb

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object

Tests if there are any records present which conform to the argument filter(s) def exists?(*args)

super if defined?(super) && args.size == 0
where(*args).exists?

end

Parameters:

  • args (Object)

    a filter condition. This argument has the same usage as the where method



11
12
13
14
15
16
17
18
19
20
# File 'lib/believer/finder_methods.rb', line 11

def find(*args)
  return where(args[0]).first if args[0].is_a?(Hash)

  if primary_key_columns.size == 1
    return where(primary_key_columns[0] => args).to_a if args.is_a?(Array) && args.size > 1
    return where(primary_key_columns[0] => args[0]).first
  end

  nil
end