Module: Filemaker::Model::Selectable
- Included in:
- Criteria
- Defined in:
- lib/filemaker/model/selectable.rb
Instance Method Summary collapse
- #custom_query(criterion) ⇒ Object
-
#find(criterion) ⇒ Filemaker::Model::Criteria, Filemaker::Model
Find records based on model ID.
-
#in(criterion, negating = false) {|options| ... } ⇒ Filemaker::Model::Criteria
Find records based on FileMaker’s compound find syntax.
-
#not_in(criterion) ⇒ Object
Simply append ‘-omit’ => true to all criteria.
-
#or(criterion) {|options| ... } ⇒ Filemaker::Model::Criteria
Used with ‘where` to specify how the queries are combined.
-
#recid(id) ⇒ Object
Using FileMaker’s internal ID to find the record.
-
#where(criterion) {|options| ... } ⇒ Filemaker::Model::Criteria
Find records based on query hash.
Instance Method Details
#custom_query(criterion) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/filemaker/model/selectable.rb', line 127 def custom_query(criterion) chains.push(:custom) chains.delete(:where) chains.delete(:in) @selector = criterion self end |
#find(criterion) ⇒ Filemaker::Model::Criteria, Filemaker::Model
Find records based on model ID. If passed a hash, will use ‘where`. On the last resort, if we seriously can’t find using ‘where`, we find it thru the `recid`. Is this a good design? We will see in production. Performance note: 2 HTTP requests if going that last resort route.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/filemaker/model/selectable.rb', line 38 def find(criterion) return where(criterion) if criterion.is_a? Hash # Find using model ID (may not be the -recid) id = criterion.to_s.gsub(/\A=*/, '=') # Always append '=' for ID # If we are finding with ID, we just limit to one and return # immediately. Last resort is to use the recid to find. where(klass.identity.name => id).first || recid(criterion) end |
#in(criterion, negating = false) {|options| ... } ⇒ Filemaker::Model::Criteria
Find records based on FileMaker’s compound find syntax.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/filemaker/model/selectable.rb', line 107 def in(criterion, negating = false) if chains.include?(:where) raise Filemaker::Errors::MixedClauseError, "Can't mix 'in' with 'where'." end chains.push(:in) chains.delete(:where) @selector ||= [] become_array(criterion).each do |hash| accepted_hash = klass.with_model_fields(hash) accepted_hash['-omit'] = true if negating @selector << accepted_hash end yield if block_given? self end |
#not_in(criterion) ⇒ Object
Simply append ‘-omit’ => true to all criteria
136 137 138 |
# File 'lib/filemaker/model/selectable.rb', line 136 def not_in(criterion) self.in(criterion, true) end |
#or(criterion) {|options| ... } ⇒ Filemaker::Model::Criteria
Used with ‘where` to specify how the queries are combined. Default is ’and’, so you won’t find any ‘and` method.
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/filemaker/model/selectable.rb', line 149 def or(criterion) if chains.include?(:in) raise Filemaker::Errors::MixedClauseError, "Can't mix 'or' with 'in'." end @selector ||= {} selector.merge!(klass.with_model_fields(criterion)) [:lop] = 'or' yield if block_given? self end |
#recid(id) ⇒ Object
Using FileMaker’s internal ID to find the record.
50 51 52 53 54 55 56 57 |
# File 'lib/filemaker/model/selectable.rb', line 50 def recid(id) return nil if id.blank? @selector = {} # We want to clear the selector when it comes to recid selector['-recid'] = id chains.push(:where) unless chains.include?(:where) # No double :where first end |
#where(criterion) {|options| ... } ⇒ Filemaker::Model::Criteria
Find records based on query hash.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/filemaker/model/selectable.rb', line 9 def where(criterion) if chains.include?(:in) raise Filemaker::Errors::MixedClauseError, "Can't mix 'where' with 'in'." end chains.push(:where) chains.delete(:in) @selector ||= {} selector.merge!(klass.with_model_fields(criterion)) yield if block_given? self end |