Module: ActiveHouse::Selectable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Chainable
- Defined in:
- lib/active_house/selectable.rb
Instance Method Summary collapse
Instance Method Details
#initialize ⇒ Object
17 18 19 20 |
# File 'lib/active_house/selectable.rb', line 17 def initialize(*) @fields = [] super end |
#select(*fields) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_house/selectable.rb', line 22 def select(*fields) raise ArgumentError, 'wrong number of arguments' if fields.empty? formatted_fields = fields.map do |field| if field.is_a?(Symbol) && model_class._attribute_opts.key?(field) opts = model_class._attribute_opts.fetch(field) opts.key?(:select) ? "#{opts[:select]} AS #{field}" : field.to_s else field.to_s end end chain_query fields: (@fields + formatted_fields).uniq end |