mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Fixed #12386 -- Corrected the column names produced for autogenerated m2m tables when the related table is specified as a dot-separated string. Thanks to ldevesine for the report and simonb for the extra test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12226 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -881,8 +881,8 @@ def create_many_to_many_intermediary_model(field, klass): | ||||
|     from django.db import models | ||||
|     managed = True | ||||
|     if isinstance(field.rel.to, basestring) and field.rel.to != RECURSIVE_RELATIONSHIP_CONSTANT: | ||||
|         to = field.rel.to | ||||
|         to_model = field.rel.to | ||||
|         to = to_model.split('.')[-1] | ||||
|         def set_managed(field, model, cls): | ||||
|             field.rel.through._meta.managed = model._meta.managed or cls._meta.managed | ||||
|         add_lazy_relation(klass, field, to_model, set_managed) | ||||
|   | ||||
| @@ -50,6 +50,31 @@ __test__ = {'API_TESTS': """ | ||||
| >>> ad.publications.count() | ||||
| 1 | ||||
|  | ||||
| # Regression for #12386 - field names on the autogenerated intermediate class | ||||
| # that are specified as dotted strings don't retain any path component for the | ||||
| # field or column name | ||||
|  | ||||
| >>> Article.publications.through._meta.fields[1].name | ||||
| 'article' | ||||
|  | ||||
| >>> Article.publications.through._meta.fields[1].get_attname_column() | ||||
| ('article_id', 'article_id') | ||||
|  | ||||
| >>> Article.publications.through._meta.fields[2].name | ||||
| 'publication' | ||||
|  | ||||
| >>> Article.publications.through._meta.fields[2].get_attname_column() | ||||
| ('publication_id', 'publication_id') | ||||
|  | ||||
| >>> Article._meta.get_field('publications').m2m_db_table() | ||||
| 'model_package_article_publications' | ||||
|  | ||||
| >>> Article._meta.get_field('publications').m2m_column_name() | ||||
| 'article_id' | ||||
|  | ||||
| >>> Article._meta.get_field('publications').m2m_reverse_name() | ||||
| 'publication_id' | ||||
|  | ||||
| """} | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user