class Miguel::Schema::ForeignKey
Class representing foreign key constraint.
Constants
- IGNORED_OPTS
Options we ignore when comparing. These are usually tied to the underlying column, not constraint.
Attributes
columns[R]
Key's column(s), the target table name and options.
opts[R]
Key's column(s), the target table name and options.
table_name[R]
Key's column(s), the target table name and options.
Public Class Methods
new( columns, table_name, opts = {} )
click to toggle source
Create new foreign key for given columns referring to given table.
# File lib/miguel/schema.rb, line 249 def initialize( columns, table_name, opts = {} ) @columns = [ *columns ] @table_name = table_name @opts = opts if key = opts[ :key ] opts[ :key ] = [ *key ] end end
Public Instance Methods
==(other)
click to toggle source
Compare one foreign key with another one.
# File lib/miguel/schema.rb, line 270 def == other other.is_a?( ForeignKey ) && columns == other.columns && table_name == other.table_name && canonic_opts == other.canonic_opts end
canonic_opts()
click to toggle source
Get the foreign key options, in a canonic way.
# File lib/miguel/schema.rb, line 263 def canonic_opts o = { :on_update => :no_action, :on_delete => :no_action } o.merge!( opts ) o.delete_if{ |key, value| IGNORED_OPTS.include? key } end
dump( out )
click to toggle source
Dump foreign key definition.
# File lib/miguel/schema.rb, line 278 def dump( out ) out << "foreign_key #{out_columns}, #{out_table_name}#{out_opts}" end