Module: NinjaModel::FinderMethods

Included in:
Relation
Defined in:
lib/ninja_model/relation/finder_methods.rb

Instance Method Summary collapse

Instance Method Details

#all(*args) ⇒ Object



12
13
14
# File 'lib/ninja_model/relation/finder_methods.rb', line 12

def all(*args)
  args.any? ? apply_finder_options(args.first).to_a : to_a
end

#exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/ninja_model/relation/finder_methods.rb', line 31

def exists?(id)
  where(primary_key.to_sym => id).limit(1)
  relation.first ? true : false
end

#find(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ninja_model/relation/finder_methods.rb', line 16

def find(*args)
  options = args.extract_options!

  if options.present?
    apply_finder_options(options).find(*args)
  else
    case args.first
    when :first, :all
      send(args.first)
    else
      find_with_ids(*args)
    end
  end
end

#first(*args) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/ninja_model/relation/finder_methods.rb', line 4

def first(*args)
  if args.any?
    apply_finder_options(args.first).limit(1).to_a.first
  else
    find_first
  end
end