Class: ActiveSchema::Associations::ByReverseForeignKey

Inherits:
ByForeignKey
  • Object
show all
Defined in:
lib/active_schema/associations/by_foreign_key.rb

Instance Method Summary collapse

Methods inherited from ByForeignKey

#association, #initialize

Methods included from Naming

#name_for, #plural_name_for

Constructor Details

This class inherits a constructor from ActiveSchema::Associations::ByForeignKey

Instance Method Details

#generateObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_schema/associations/by_foreign_key.rb', line 35

def generate
  if @key_column_unique
    association @to_model, :has_one,
      name_for(@from_model),
      { :class_name => @from_model.name, :foreign_key => @key_column }
  else
    association @to_model, :has_many, 
      plural_name_for(@from_model),
      { :class_name => @from_model.name, :foreign_key => @key_column }
  end

end