{% set js_msg = '' %}
{% set this_params = null %}
{% if one_key['constraint'] is defined %}
{% set drop_fk_query = 'ALTER TABLE ' ~ backquote(db) ~ '.' ~ backquote(table)
~ ' DROP FOREIGN KEY '
~ backquote(one_key['constraint']) ~ ';'
%}
{% set this_params = url_params %}
{% set this_params = {
'goto': url('/table/relation'),
'back': url('/table/relation'),
'sql_query': drop_fk_query,
'message_to_show': 'Foreign key constraint %s has been dropped'|trans|format(
one_key['constraint']
)
} %}
{% set js_msg = 'ALTER TABLE ' ~ db ~ '.' ~ table ~ ' DROP FOREIGN KEY ' ~ one_key['constraint'] ~ ';' %}
{% endif %}
{% if one_key['constraint'] is defined %}
{% set drop_str = get_icon('b_drop', 'Drop'|trans) %}
{{ link_or_button(url('/sql'), this_params, drop_str, {'class': 'drop_foreign_key_anchor ajax'}) }}
{% endif %}
{# For ON DELETE and ON UPDATE, the default action
is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE
won't display the clause if it's set as RESTRICT. #}
{% set on_delete = one_key['on_delete'] is defined
? one_key['on_delete'] : 'RESTRICT' %}
{% set on_update = one_key['on_update'] is defined
? one_key['on_update'] : 'RESTRICT' %}
{% include 'table/relation/dropdown_generate.twig' with {
'dropdown_question': 'ON DELETE',
'select_name': 'on_delete[' ~ i ~ ']',
'choices': options_array,
'selected_value': on_delete
} only %}
{% include 'table/relation/dropdown_generate.twig' with {
'dropdown_question': 'ON UPDATE',
'select_name': 'on_update[' ~ i ~ ']',
'choices': options_array,
'selected_value': on_update
} only %}
{% if one_key['index_list'] is defined %}
{% for key, column in one_key['index_list'] %}
{% include 'table/relation/dropdown_generate.twig' with {
'dropdown_question': '',
'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
'choices': column_array,
'selected_value': column
} only %}
{% endfor %}
{% else %}
{% include 'table/relation/dropdown_generate.twig' with {
'dropdown_question': '',
'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
'choices': column_array,
'selected_value': ''
} only %}
{% endif %}
{% trans '+ Add column' %}
{% set tables = [] %}
{% if foreign_db %}
{% set tables = get_tables(foreign_db, tbl_storage_engine) %}
{% else %}
{% set tables = get_tables(db, tbl_storage_engine) %}
{% endif %}
{% include 'table/relation/relational_dropdown.twig' with {
'name': 'destination_foreign_db[' ~ i ~ ']',
'title': 'Database'|trans,
'values': databases,
'foreign': foreign_db,
'db': db
} only %}
{% include 'table/relation/relational_dropdown.twig' with {
'name': 'destination_foreign_table[' ~ i ~ ']',
'title': 'Table'|trans,
'values': tables,
'foreign': foreign_table
} only %}
{% if foreign_db and foreign_table %}
{% for foreign_column in one_key['ref_index_list'] %}
{% include 'table/relation/relational_dropdown.twig' with {
'name': 'destination_foreign_column[' ~ i ~ '][]',
'title': 'Column'|trans,
'values': unique_columns,
'foreign': foreign_column
} only %}
{% endfor %}
{% else %}
{% include 'table/relation/relational_dropdown.twig' with {
'name': 'destination_foreign_column[' ~ i ~ '][]',
'title': 'Column'|trans,
'values': [],
'foreign': ''
} only %}
{% endif %}