Class: ActiveForce::ActiveQuery

Inherits:
Query
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/active_force/active_query.rb

Instance Attribute Summary collapse

Attributes inherited from Query

#table

Instance Method Summary collapse

Methods inherited from Query

#fields, #find, #first, #join, #last, #limit_value, #offset, #offset_value, #order, #to_s

Constructor Details

#initialize(sobject) ⇒ ActiveQuery

Returns a new instance of ActiveQuery.



14
15
16
17
18
# File 'lib/active_force/active_query.rb', line 14

def initialize sobject
  @sobject = sobject
  super table_name
  fields sobject.fields
end

Instance Attribute Details

#sobjectObject (readonly)

Returns the value of attribute sobject.



9
10
11
# File 'lib/active_force/active_query.rb', line 9

def sobject
  @sobject
end

Instance Method Details

#countObject



26
27
28
29
# File 'lib/active_force/active_query.rb', line 26

def count
  super
  sfdc_client.query(to_s).first.expr0
end

#find_by(conditions) ⇒ Object



47
48
49
# File 'lib/active_force/active_query.rb', line 47

def find_by conditions
  where(conditions).limit 1
end

#includes(*relations) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/active_force/active_query.rb', line 51

def includes(*relations)
  relations.each do |relation|
    association = sobject.associations[relation]
    fields Association::EagerLoadProjectionBuilder.build association
  end
  self
end

#limit(limit) ⇒ Object



31
32
33
34
# File 'lib/active_force/active_query.rb', line 31

def limit limit
  super
  limit == 1 ? to_a.first : self
end

#noneObject



59
60
61
62
# File 'lib/active_force/active_query.rb', line 59

def none
  @records = []
  where(id: '1'*18).where(id: '0'*18)
end

#select(*fields) ⇒ Object



42
43
44
45
# File 'lib/active_force/active_query.rb', line 42

def select *fields
  fields.map! { |field| mappings[field] }
  super *fields
end

#to_aObject Also known as: all



20
21
22
# File 'lib/active_force/active_query.rb', line 20

def to_a
  @records ||= result.to_a.map { |mash| build mash }
end

#where(args = nil, *rest) ⇒ Object



36
37
38
39
40
# File 'lib/active_force/active_query.rb', line 36

def where args=nil, *rest
  return self if args.nil?
  super build_condition args, rest
  self
end