Class: ActiveRecord::QueryMethods::WhereChain
- Inherits:
-
Object
- Object
- ActiveRecord::QueryMethods::WhereChain
- Defined in:
- lib/pgrel/active_record/query_methods.rb
Overview
Extend WhereChain with ‘store’ method.
Instance Method Summary collapse
Instance Method Details
#store(store_name, *opts) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pgrel/active_record/query_methods.rb', line 13 def store(store_name, *opts) store_name = store_name.to_s column = @scope.klass.columns_hash[store_name] # Rails 4 column has method 'array' # but Rails 5 has 'array?'. # # So, check both( if (arr = column.try(:array)) || (arr.nil? && column.array?) klass = ArrayChain else column_klass = column.type.capitalize klass = "ActiveRecord::QueryMethods::#{column_klass}Chain".constantize end chain = klass.new(@scope, store_name) return chain.where(*opts) unless opts.empty? chain end |