Module: Polyamorous::ReflectionExtensions

Defined in:
lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb

Instance Method Summary collapse

Instance Method Details

#build_join_constraint(table, foreign_table) ⇒ Object


12
13
14
15
16
17
18
# File 'lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb', line 12

def build_join_constraint(table, foreign_table)
  if polymorphic?
    super.and(foreign_table[foreign_type].eq(klass.name))
  else
    super
  end
end

#join_scope(table, foreign_table, foreign_klass) ⇒ Object


4
5
6
7
8
9
10
# File 'lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb', line 4

def join_scope(table, foreign_table, foreign_klass)
  if respond_to?(:polymorphic?) && polymorphic?
    super.where!(foreign_table[foreign_type].eq(klass.name))
  else
    super
  end
end