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
whereto 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
118 119 120 121 122 123 124 |
# File 'lib/filemaker/model/selectable.rb', line 118 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.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/filemaker/model/selectable.rb', line 35 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.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/filemaker/model/selectable.rb', line 101 def in(criterion, negating = false) raise Filemaker::Errors::MixedClauseError, "Can't mix 'in' with 'where'." if chains.include?(:where) chains.push(:in) chains.delete(:where) @selector ||= [] become_array(criterion).each do |hash| accepted_hash = klass.with_model_fields(hash) accepted_hash.merge!('-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
127 128 129 |
# File 'lib/filemaker/model/selectable.rb', line 127 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.
140 141 142 143 144 145 146 147 148 |
# File 'lib/filemaker/model/selectable.rb', line 140 def or(criterion) raise Filemaker::Errors::MixedClauseError, "Can't mix 'or' with 'in'." if chains.include?(:in) @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.
47 48 49 50 51 52 53 54 |
# File 'lib/filemaker/model/selectable.rb', line 47 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 |
# File 'lib/filemaker/model/selectable.rb', line 9 def where(criterion) raise Filemaker::Errors::MixedClauseError, "Can't mix 'where' with 'in'." if chains.include?(:in) chains.push(:where) chains.delete(:in) @selector ||= {} selector.merge!(klass.with_model_fields(criterion)) yield if block_given? self end |