summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/introspection.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-01-10 20:27:30 +0100
committerClaude Paroz <claude@2xlibre.net>2015-01-12 19:58:47 +0100
commit4c413e231cfe788de6e371567f395c8ccbd26103 (patch)
tree8b2100a8d9d650546615c8c1cd3b8f52251690a3 /django/db/backends/mysql/introspection.py
parentb75c707943e159b80c179c538721406bbfb8b120 (diff)
downloaddjango-4c413e231cfe788de6e371567f395c8ccbd26103.tar.gz
Fixed #17785 -- Preferred column names in get_relations introspection
Thanks Thomas Güttler for the report and the initial patch, and Tim Graham for the review.
Diffstat (limited to 'django/db/backends/mysql/introspection.py')
-rw-r--r--django/db/backends/mysql/introspection.py16
1 files changed, 3 insertions, 13 deletions
diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py
index 30ac6d4cab..3ff28cf673 100644
--- a/django/db/backends/mysql/introspection.py
+++ b/django/db/backends/mysql/introspection.py
@@ -80,25 +80,15 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
)
return fields
- def _name_to_index(self, cursor, table_name):
- """
- Returns a dictionary of {field_name: field_index} for the given table.
- Indexes are 0-based.
- """
- return {d[0]: i for i, d in enumerate(self.get_table_description(cursor, table_name))}
-
def get_relations(self, cursor, table_name):
"""
- Returns a dictionary of {field_index: (field_index_other_table, other_table)}
- representing all relationships to the given table. Indexes are 0-based.
+ Returns a dictionary of {field_name: (field_name_other_table, other_table)}
+ representing all relationships to the given table.
"""
- my_field_dict = self._name_to_index(cursor, table_name)
constraints = self.get_key_columns(cursor, table_name)
relations = {}
for my_fieldname, other_table, other_field in constraints:
- other_field_index = self._name_to_index(cursor, other_table)[other_field]
- my_field_index = my_field_dict[my_fieldname]
- relations[my_field_index] = (other_field_index, other_table)
+ relations[my_fieldname] = (other_field, other_table)
return relations
def get_key_columns(self, cursor, table_name):