Sha256: 5d04179a51c71c6644405abb4dce09330c6a9817ef84d06b84e073b3a1c6f9dd
Contents?: true
Size: 1.02 KB
Versions: 3
Compression:
Stored size: 1.02 KB
Contents
# active_record_5.1_ruby_2/join_association.rb module Polyamorous module JoinAssociationExtensions include SwappingReflectionClass def self.prepended(base) base.class_eval { attr_reader :join_type } end def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin) @join_type = join_type if polymorphic_class && ::ActiveRecord::Base > polymorphic_class swapping_reflection_klass(reflection, polymorphic_class) do |reflection| super(reflection, children) self.reflection.options[:polymorphic] = true end else super(reflection, children) end end def build_constraint(klass, table, key, foreign_table, foreign_key) if reflection.polymorphic? super(klass, table, key, foreign_table, foreign_key) .and(foreign_table[reflection.foreign_type].eq(reflection.klass.name)) else super(klass, table, key, foreign_table, foreign_key) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems