class ThroughHierarchy::Associations::HasUniq

Private Instance Methods

get_joins() click to toggle source
# File lib/through_hierarchy/associations/has_uniq.rb, line 24
def get_joins
  @associated.join_best_rank(group_by: @uniq)
end
get_matches(instance) click to toggle source

Use subquery method to select best hierarchy match for each @uniq Order by @uniq can result in better performance than default order (id)

# File lib/through_hierarchy/associations/has_uniq.rb, line 13
def get_matches(instance)
  associated_instance = @associated.with_instance(instance)
  arel = @associated.with_instance(instance).select_best_rank(group_by: @uniq)
  result = foreign_class.
    where(associated_instance.filters).
    joins(arel.join_sources).
    order(arel.orders)
  arel.constraints.each{|cc| result = result.where(cc)}
  return result
end
set_options(options) click to toggle source
# File lib/through_hierarchy/associations/has_uniq.rb, line 6
def set_options(options)
  super
  @uniq = options[:uniq]
end