Method: OccamsRecord.query
- Defined in:
- lib/occams-record/query.rb
.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
.query(Widget.order("name"))
.eager_load(:category)
.eager_load(:order_items, ->(q) { q.select("widget_id, order_id") }) {
eager_load(:orders) {
eager_load(:customer, ->(q) { q.select("name") })
}
}
.run
24 25 26 |
# File 'lib/occams-record/query.rb', line 24 def self.query(scope, use: nil, active_record_fallback: nil, query_logger: nil) Query.new(scope, use: use, query_logger: query_logger, active_record_fallback: active_record_fallback) end |