class TableSaw::Associations
Attributes
manifest[R]
Public Class Methods
new(manifest)
click to toggle source
# File lib/table_saw/associations.rb, line 7 def initialize(manifest) @manifest = manifest end
Public Instance Methods
belongs_to()
click to toggle source
# File lib/table_saw/associations.rb, line 11 def belongs_to @belongs_to ||= foreign_keys.each_with_object(Hash.new { |h, k| h[k] = Set.new }) do |fk, memo| memo[fk.from_table].add(fk) end end
has_many()
click to toggle source
# File lib/table_saw/associations.rb, line 17 def has_many @has_many ||= foreign_keys.each_with_object(Hash.new { |h, k| h[k] = Set.new }) do |fk, memo| memo[fk.to_table].add(fk) end end
Private Instance Methods
foreign_keys()
click to toggle source
# File lib/table_saw/associations.rb, line 25 def foreign_keys @foreign_keys ||= manifest_foreign_keys + schema_foreign_keys end
manifest_foreign_keys()
click to toggle source
# File lib/table_saw/associations.rb, line 29 def manifest_foreign_keys manifest.foreign_keys.map do |fk| TableSaw::ForeignKey.new(from_table: fk['from_table'], from_column: fk['from_column'], to_table: fk['to_table'], to_column: fk['to_column']) end end
schema_foreign_keys()
click to toggle source
# File lib/table_saw/associations.rb, line 36 def schema_foreign_keys TableSaw.information_schema.foreign_key_relationships.foreign_keys end