Sha256: d70e1f1db975356b9ce7637d999f45c876b9011b1d4af44a98091177292a424b
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
module Traits class Association module Join def from_table from.arel end def from_table_name from_table.name.to_sym end def from_table_alias from_table.table_alias.try(:to_sym) end def from_key from_table[from_key_name] end def from_key_name if polymorphic? reflection.foreign_key.to_sym elsif through? through_association.from_key_name elsif features.translates_with_globalize? nil elsif belongs_to? reflection.foreign_key.to_sym end || reflection.active_record_primary_key.to_sym end def to_table unless polymorphic? table = to.arel.clone if self_to_self? table.table_alias = "#{plural_name}_#{from.table_name}" end table end end def to_table_name unless polymorphic? to_table.name.to_sym end end def to_table_alias unless polymorphic? to_table.table_alias.try(:to_sym) end end def to_key to_table.try(:[], to_key_name) end def to_key_name unless polymorphic? if through? source_association.to_key_name elsif belongs_to? || has_and_belongs_to_many? reflection.association_primary_key.to_sym else reflection.foreign_key.to_sym end end end def to_hash super.merge!( from_table_name: from_table_name, from_table_alias: from_table_alias, from_key_name: from_key_name, to_table_name: to_table_name, to_table_alias: to_table_alias, to_key_name: to_key_name ) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord-traits-1.0.0 | lib/traits/concerns/association/join.rb |