Class: ForeignKeyNode

Inherits:
Node
  • Object
show all
Defined in:
lib/code_generator.rb

Instance Method Summary collapse

Methods inherited from Node

#column

Constructor Details

#initialize(col, table, *actions) ⇒ ForeignKeyNode

Returns a new instance of ForeignKeyNode.



276
277
278
279
280
281
282
# File 'lib/code_generator.rb', line 276

def initialize col, table, *actions
  @col = col
  @table = table
  if actions.count > 0
    @action = actions[0]
  end
end

Instance Method Details

#genObject



284
285
286
287
288
289
290
# File 'lib/code_generator.rb', line 284

def gen
  col = @col.gen
  table_name = @table.gen
  class_name = @table.table_to_class
  key = @table.key_name
  "belongs_to :#{table_name}, foreign_key: '#{col}', class: '#{class_name}', primary_key: '#{key}'"
end