Method: OccamsRecord.query

Defined in:

.query(scope, use: nil, active_record_fallback: nil, query_logger: nil) ⇒ OccamsRecord::Query

Starts building a OccamsRecord::Query. Pass it a scope from any of ActiveRecord’s query builder methods or associations. If you want to eager loaded associations, do NOT use ActiveRecord for it. Instead use OccamsRecord::Query#eager_load. Finally, call ‘run` (or any Enumerable method) to run the query and get back an array of objects.

results = OccamsRecord
  .eager_load(:order_items, ->(q) {"widget_id, order_id") }) {
    eager_load(:orders) {
      eager_load(:customer, ->(q) {"name") })


  • scope (ActiveRecord::Relation)
  • use (Module) (defaults to: nil)

    optional Module to include in the result class

  • query_logger (Array) (defaults to: nil)

    (optional) an array into which all queries will be inserted for logging/debug purposes

  • active_record_fallback (Symbol) (defaults to: nil)

    If passed, missing methods will be forwarded to an ActiveRecord instance. Options are :lazy (allow lazy loading in the AR record) or :strict (require strict loading)


# File 'lib/occams-record/query.rb', line 24

def self.query(scope, use: nil, active_record_fallback: nil, query_logger: nil), use: use, query_logger: query_logger, active_record_fallback: active_record_fallback)