Flowdock
method

foreign_keys

Importance_0
v4.2.9 - Show latest stable - 0 notes - Class: AbstractMysqlAdapter
foreign_keys(table_name) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb, line 544
      def foreign_keys(table_name)
        fk_info = select_all           SELECT fk.referenced_table_name as 'to_table'                ,fk.referenced_column_name as 'primary_key'                ,fk.column_name as 'column'                ,fk.constraint_name as 'name'          FROM information_schema.key_column_usage fk          WHERE fk.referenced_column_name is not null            AND fk.table_schema = '#{@config[:database]}'            AND fk.table_name = '#{table_name}'.strip_heredoc

        create_table_info = select_one("SHOW CREATE TABLE #{quote_table_name(table_name)}")["Create Table"]

        fk_info.map do |row|
          options = {
            column: row['column'],
            name: row['name'],
            primary_key: row['primary_key']
          }

          options[:on_update] = extract_foreign_key_action(create_table_info, row['name'], "UPDATE")
          options[:on_delete] = extract_foreign_key_action(create_table_info, row['name'], "DELETE")

          ForeignKeyDefinition.new(table_name, row['to_table'], options)
        end
      end
Register or log in to add new notes.