Module: ActiveRecord::RelationExtender
- Included in:
- Relation
- Defined in:
- lib/opt_ar/core_ext/active_record/relation.rb
Overview
Adding functionality to ActiveRecord::Relation to make
optars method available for all relations,
returning array of `OAR`s which we generate
Constant Summary collapse
- DEFAULT_QUERY_OPTIONS =
{ symbolize_keys: true, # Returns attributes with symbolized keys as: :hash, # Returns rows as Hash objects cast_booleans: true, # Typecasts TINYINT columns database_timezone: ActiveRecord::Base.default_timezone, cache_rows: false # Disabled because iteration happens only once allowing GC to cleanup }.freeze
Instance Method Summary collapse
- #optars(options = {}) ⇒ Object (also: #opt_ar_objects)
Instance Method Details
#optars(options = {}) ⇒ Object Also known as: opt_ar_objects
15 16 17 18 19 20 21 |
# File 'lib/opt_ar/core_ext/active_record/relation.rb', line 15 def optars( = {}) attrs = [:attrs] || [] validate_columns(attrs) select_attrs = ([primary_key] + attrs).uniq sql_query = except(:select).select(select_attrs).to_sql fetch_objects(sql_query, select_attrs) end |