Sha256: 73d895a6dffa012814b319cee800028a9b213d662b1115061aee0da8fadcdc84
Contents?: true
Size: 805 Bytes
Versions: 3
Compression:
Stored size: 805 Bytes
Contents
module ActiveHouse module ArrayJoinable extend ActiveSupport::Concern included do private def build_array_join_query_part "ARRAY JOIN #{@array_joins.join(', ')}" unless @array_joins.empty? end end def initialize(*) @array_joins = [] super end def array_join(*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 array_joins: (@array_joins + formatted_fields).uniq end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
active_house-0.4.0 | lib/active_house/array_joinable.rb |
active_house-0.3.2 | lib/active_house/array_joinable.rb |
active_house-0.3.1 | lib/active_house/array_joinable.rb |