Method: HasDynamicColumns::ActiveRecord::QueryMethods::OrderChain#by_dynamic_columns

Defined in:
lib/has_dynamic_columns/active_record/query_methods.rb

#by_dynamic_columns(*args) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/has_dynamic_columns/active_record/query_methods.rb', line 203

def by_dynamic_columns(*args)
  @scope.send(:preprocess_order_args, args)

  # Add now - want to keep the order with the regular column orders
  @scope.order_values += args

  # Map
  dynamic_columns_value = {
    :scope => nil,
    :order => args,
  }
  @scope.order_dynamic_columns_values = dynamic_columns_value

  chain = ::ActiveRecord::QueryMethods::OrderChain.new(@scope)
  chain.instance_eval do
    # Make outer scope variable accessible
    @dynamic_columns_value = dynamic_columns_value

    # Extends where to chain with a has_scope method
    # This scopes the where from above
    def with_scope(opt)
      @dynamic_columns_value[:scope] = opt

      @scope
    end
  end

  chain
end