Class: Straitjacket::ForeignKeyConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/straitjacket.rb

Instance Attribute Summary

Attributes inherited from Constraint

#column, #content, #name, #options, #table

Instance Method Summary collapse

Methods inherited from Constraint

#apply, #initialize

Constructor Details

This class inherits a constructor from Straitjacket::Constraint

Instance Method Details

#sqlObject



116
117
118
119
120
121
122
123
# File 'lib/straitjacket.rb', line 116

def sql
  more = ""
  if options[:references]
    on = options[:on] ? %[("#{options[:on]}")] : ""
    more = %[REFERENCES "#{options[:references]}"#{on}]
  end
  %[ALTER TABLE "#{table}" ADD CONSTRAINT "#{name}" FOREIGN KEY ("#{column}") #{more} MATCH FULL]
end