Module: QuickbaseRecord::Queries::ClassMethods

Defined in:
lib/quickbase_record/queries.rb

Instance Method Summary collapse

Instance Method Details

#build_query(query_hash) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/quickbase_record/queries.rb', line 54

def build_query(query_hash)
  return convert_query_string(query_hash) if query_hash.is_a? String

  query_hash.map do |field_name, values|
    fid = convert_field_name_to_fid(field_name)
    if values.is_a? Array
      join_with_or(fid, values)
    elsif values.is_a? Hash
      join_with_custom(fid, values)
    else
      join_with_and(fid, values)
    end
  end.join("AND")
end

#clistObject



15
16
17
# File 'lib/quickbase_record/queries.rb', line 15

def clist
  @clist ||= fields.reject{ |field_name| field_name == :dbid }.values.join('.')
end

#create(attributes = {}) ⇒ Object

Raises:

  • (StandardErrror)


38
39
40
41
42
43
# File 'lib/quickbase_record/queries.rb', line 38

def create(attributes={})
  raise StandardErrror, "You cannot call #{self}.create() with an :id attribute" if attributes.include?(:id)
  object = new(attributes)
  object.save
  return object
end

#dbidObject



11
12
13
# File 'lib/quickbase_record/queries.rb', line 11

def dbid
  @dbid ||= fields[:dbid]
end

#find(id) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/quickbase_record/queries.rb', line 19

def find(id)
  query_options = { query: build_query(id: id), clist: clist }
  query_response = qb_client.do_query(dbid, query_options).first

  return nil if query_response.nil?

  converted_response = convert_quickbase_response(query_response)
  new(converted_response)
end

#qid(id) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/quickbase_record/queries.rb', line 45

def qid(id)
  query_options = { qid: id, clist: clist }
  query_response = qb_client.do_query(dbid, query_options)

  return [] if query_response.first.nil?

  build_array_of_new_objects(query_response)
end

#where(query_hash) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/quickbase_record/queries.rb', line 29

def where(query_hash)
  query_options = { query: build_query(query_hash), clist: clist }
  query_response = qb_client.do_query(dbid, query_options)

  return [] if query_response.first.nil?

  build_array_of_new_objects(query_response)
end