Module: FlexiModel::ArQueryable::ClassMethods
- Defined in:
- lib/flexi_model/ar_queryable.rb
Instance Method Summary collapse
-
#all ⇒ Object
Load all records from the model.
-
#count ⇒ Object
Return count of items from the model.
-
#find(id_or_ids) ⇒ Object
Find a record instance by id Returns model instance.
-
#first ⇒ Object
Load first record from the model.
-
#last ⇒ Object
Load last record from the model.
-
#length ⇒ Object
Alias to :count.
-
#where(conditions = {}) ⇒ Object
Apply conditions using hash map.
Instance Method Details
#all ⇒ Object
Load all records from the model
35 36 37 |
# File 'lib/flexi_model/ar_queryable.rb', line 35 def all _build_criteria end |
#count ⇒ Object
Return count of items from the model
9 10 11 |
# File 'lib/flexi_model/ar_queryable.rb', line 9 def count _build_criteria.count end |
#find(id_or_ids) ⇒ Object
Find a record instance by id Returns model instance
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flexi_model/ar_queryable.rb', line 20 def find(id_or_ids) records = RECORD.includes(:values).where(id: id_or_ids) if records.present? if id_or_ids.is_a?(Array) records.map { |_record| initialize_with_record(_record) } else initialize_with_record(records.first) end else nil end end |
#first ⇒ Object
Load first record from the model
40 41 42 |
# File 'lib/flexi_model/ar_queryable.rb', line 40 def first _build_criteria.first end |
#last ⇒ Object
Load last record from the model
45 46 47 |
# File 'lib/flexi_model/ar_queryable.rb', line 45 def last _build_criteria.last end |
#length ⇒ Object
Alias to :count
14 15 16 |
# File 'lib/flexi_model/ar_queryable.rb', line 14 def length; self.count end |
#where(conditions = {}) ⇒ Object
Apply conditions using hash map
50 51 52 |
# File 'lib/flexi_model/ar_queryable.rb', line 50 def where(conditions = {}) _build_criteria.where(conditions) end |