Class: PatternQueryHelper::Associations

Inherits:
Object
  • Object
show all
Defined in:
lib/pattern_query_helper/associations.rb

Class Method Summary collapse

Class Method Details

.load_associations(payload, associations) ⇒ Object



12
13
14
15
# File 'lib/pattern_query_helper/associations.rb', line 12

def self.load_associations(payload, associations)
  ActiveRecord::Associations::Preloader.new.preload(payload, associations)
  payload.as_json(include: associations)
end

.process_association_params(params) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/pattern_query_helper/associations.rb', line 3

def self.process_association_params(params)
  associations = params[:include] || []
  if associations.class == String
    return [associations.to_sym]
  else
    return associations.map { |x| x.to_sym }
  end
end