module Traits::Association::Intermediate

Public Instance Methods

intermediate?() click to toggle source

class Person

has_and_belongs_to_many :groups

person_traits.associations.intermediate? => true

# File lib/traits/association/intermediate.rb, line 12
def intermediate?
  has_and_belongs_to_many?
end
intermediate_from_key() click to toggle source
# File lib/traits/association/intermediate.rb, line 41
def intermediate_from_key
  if intermediate?
    intermediate_table[intermediate_from_key_name]
  end
end
intermediate_from_key_name() click to toggle source
# File lib/traits/association/intermediate.rb, line 47
def intermediate_from_key_name
  if intermediate?
    @im_from_key_name ||= reflection.association_foreign_key.to_sym
  end
end
intermediate_table() click to toggle source
# File lib/traits/association/intermediate.rb, line 16
def intermediate_table
  Arel::Table.new(reflection.join_table) if intermediate?
end
intermediate_table_name() click to toggle source
# File lib/traits/association/intermediate.rb, line 20
def intermediate_table_name
  return unless intermediate?
  unless @im_table_name
    name           = reflection.join_table
    @im_table_name = name.kind_of?(String) ? name.to_sym : name
  end
  @im_table_name
end
intermediate_to_key() click to toggle source
# File lib/traits/association/intermediate.rb, line 29
def intermediate_to_key
  if intermediate?
    intermediate_table[intermediate_to_key_name]
  end
end
intermediate_to_key_name() click to toggle source
# File lib/traits/association/intermediate.rb, line 35
def intermediate_to_key_name
  if intermediate?
    @im_to_key_name ||= reflection.foreign_key.to_sym
  end
end
to_hash() click to toggle source
Calls superclass method
# File lib/traits/association/intermediate.rb, line 53
def to_hash
  super.merge!(
    intermediate:               intermediate?,
    intermediate_table_name:    intermediate_table_name,
    intermediate_to_key_name:   intermediate_to_key_name,
    intermediate_from_key_name: intermediate_from_key_name
  )
end