Class: ActiveRecord::ForeignKeyConstraint
- Inherits:
-
Object
- Object
- ActiveRecord::ForeignKeyConstraint
- Defined in:
- lib/foreign_key_saver/foreign_key_saver_patches.rb
Constant Summary collapse
- ACTIONS =
{ :restrict => 'RESTRICT', :no_action => 'NO ACTION', :cascade => 'CASCADE', :set_null => 'SET NULL', :set_default => 'SET DEFAULT' }.freeze
Instance Attribute Summary collapse
-
#delete_action ⇒ Object
Returns the value of attribute delete_action.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#referenced_key ⇒ Object
Returns the value of attribute referenced_key.
-
#referenced_table ⇒ Object
Returns the value of attribute referenced_table.
-
#update_action ⇒ Object
Returns the value of attribute update_action.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, key, referenced_table, referenced_key, update_action = nil, delete_action = nil) ⇒ ForeignKeyConstraint
constructor
A new instance of ForeignKeyConstraint.
- #quote_constraint_action(action) ⇒ Object
- #to_dump ⇒ Object
- #to_s ⇒ Object
- #to_sql(connection) ⇒ Object
Constructor Details
#initialize(name, key, referenced_table, referenced_key, update_action = nil, delete_action = nil) ⇒ ForeignKeyConstraint
Returns a new instance of ForeignKeyConstraint.
11 12 13 14 15 16 17 18 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 11 def initialize(name, key, referenced_table, referenced_key, update_action = nil, delete_action = nil) self.name = name self.key = key self.referenced_table = referenced_table self.referenced_key = referenced_key self.update_action = update_action self.delete_action = delete_action end |
Instance Attribute Details
#delete_action ⇒ Object
Returns the value of attribute delete_action.
9 10 11 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 9 def delete_action @delete_action end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 9 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 8 def name @name end |
#referenced_key ⇒ Object
Returns the value of attribute referenced_key.
9 10 11 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 9 def referenced_key @referenced_key end |
#referenced_table ⇒ Object
Returns the value of attribute referenced_table.
8 9 10 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 8 def referenced_table @referenced_table end |
#update_action ⇒ Object
Returns the value of attribute update_action.
9 10 11 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 9 def update_action @update_action end |
Class Method Details
.constraint_action_from_sql(action) ⇒ Object
66 67 68 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 66 def self.constraint_action_from_sql(action) ACTIONS.invert[action] || action end |
Instance Method Details
#==(other) ⇒ Object
36 37 38 39 40 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 36 def ==(other) name == other.name && key == other.key && referenced_table == other.referenced_table && referenced_key == other.referenced_key && update_action == other.update_action && delete_action == other.delete_action end |
#quote_constraint_action(action) ⇒ Object
42 43 44 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 42 def quote_constraint_action(action) ACTIONS[action.to_sym] || action.to_s end |
#to_dump ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 54 def to_dump dump = "#{key.inspect}, #{referenced_table.inspect}, #{referenced_key.inspect}" dump << ", :name => #{name.inspect}" unless name.blank? dump << ", :on_update => #{update_action.inspect}" if update_action != :restrict dump << ", :on_delete => #{delete_action.inspect}" if delete_action != :restrict dump end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 62 def to_s name end |
#to_sql(connection) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/foreign_key_saver/foreign_key_saver_patches.rb', line 46 def to_sql(connection) (name.blank? ? "" : "CONSTRAINT #{connection.quote_column_name(name)} ") + "FOREIGN KEY (#{connection.quote_column_names(key)}) " + "REFERENCES #{connection.quote_table_name(referenced_table)} (#{connection.quote_column_names(referenced_key)}) " + "ON UPDATE #{quote_constraint_action(update_action)} " + "ON DELETE #{quote_constraint_action(delete_action)}" end |