Module: Foreigner::ConnectionAdapters::Sql2003
- Included in:
- Mysql2Adapter, PostgreSQLAdapter
- Defined in:
- lib/foreigner/connection_adapters/sql2003.rb
Instance Method Summary collapse
- #add_foreign_key(from_table, to_table, options = {}) ⇒ Object
- #add_foreign_key_sql(from_table, to_table, options = {}) ⇒ Object
- #drop_table(*args) ⇒ Object
- #remove_foreign_key(table, options) ⇒ Object
- #remove_foreign_key_sql(table, options) ⇒ Object
- #supports_foreign_keys? ⇒ Boolean
Instance Method Details
#add_foreign_key(from_table, to_table, options = {}) ⇒ Object
12 13 14 15 |
# File 'lib/foreigner/connection_adapters/sql2003.rb', line 12 def add_foreign_key(from_table, to_table, = {}) sql = "ALTER TABLE #{quote_table_name(from_table)} #{add_foreign_key_sql(from_table, to_table, )}" execute(sql) end |
#add_foreign_key_sql(from_table, to_table, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/foreigner/connection_adapters/sql2003.rb', line 17 def add_foreign_key_sql(from_table, to_table, = {}) column = [:column] || "#{to_table.to_s.singularize}_id" foreign_key_name = foreign_key_name(from_table, column, ) primary_key = [:primary_key] || "id" dependency = dependency_sql([:dependent]) sql = "ADD CONSTRAINT #{quote_column_name(foreign_key_name)} " + "FOREIGN KEY (#{quote_column_name(column)}) " + "REFERENCES #{quote_table_name(ActiveRecord::Migrator.proper_table_name(to_table))}(#{primary_key})" sql << " #{dependency}" if dependency.present? sql << " #{[:options]}" if [:options] sql end |
#drop_table(*args) ⇒ Object
8 9 10 |
# File 'lib/foreigner/connection_adapters/sql2003.rb', line 8 def drop_table(*args) disable_referential_integrity { super } end |
#remove_foreign_key(table, options) ⇒ Object
33 34 35 |
# File 'lib/foreigner/connection_adapters/sql2003.rb', line 33 def remove_foreign_key(table, ) execute "ALTER TABLE #{quote_table_name(table)} #{remove_foreign_key_sql(table, )}" end |
#remove_foreign_key_sql(table, options) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/foreigner/connection_adapters/sql2003.rb', line 37 def remove_foreign_key_sql(table, ) if Hash === foreign_key_name = foreign_key_name(table, [:column], ) else foreign_key_name = foreign_key_name(table, "#{.to_s.singularize}_id") end "DROP CONSTRAINT #{quote_column_name(foreign_key_name)}" end |
#supports_foreign_keys? ⇒ Boolean
4 5 6 |
# File 'lib/foreigner/connection_adapters/sql2003.rb', line 4 def supports_foreign_keys? true end |