mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Refs #20487 -- Added test for querying mixed case fields with common related model.
Thanks Shai Berger for the review.
This commit is contained in:
parent
37c17846ad
commit
aad1833fa0
@ -449,6 +449,14 @@ class CategoryItem(models.Model):
|
||||
return "category item: " + str(self.category)
|
||||
|
||||
|
||||
class MixedCaseFieldCategoryItem(models.Model):
|
||||
CaTeGoRy = models.ForeignKey(SimpleCategory, models.CASCADE)
|
||||
|
||||
|
||||
class MixedCaseDbColumnCategoryItem(models.Model):
|
||||
category = models.ForeignKey(SimpleCategory, models.CASCADE, db_column='CaTeGoRy_Id')
|
||||
|
||||
|
||||
class OneToOneCategory(models.Model):
|
||||
new_name = models.CharField(max_length=15)
|
||||
category = models.OneToOneField(SimpleCategory, models.CASCADE)
|
||||
@ -462,6 +470,12 @@ class CategoryRelationship(models.Model):
|
||||
second = models.ForeignKey(SimpleCategory, models.CASCADE, related_name='second_rel')
|
||||
|
||||
|
||||
class CommonMixedCaseForeignKeys(models.Model):
|
||||
category = models.ForeignKey(CategoryItem, models.CASCADE)
|
||||
mixed_case_field_category = models.ForeignKey(MixedCaseFieldCategoryItem, models.CASCADE)
|
||||
mixed_case_db_column_category = models.ForeignKey(MixedCaseDbColumnCategoryItem, models.CASCADE)
|
||||
|
||||
|
||||
class NullableName(models.Model):
|
||||
name = models.CharField(max_length=20, null=True)
|
||||
|
||||
|
@ -15,17 +15,18 @@ from django.test.utils import CaptureQueriesContext
|
||||
from .models import (
|
||||
FK1, Annotation, Article, Author, BaseA, Book, CategoryItem,
|
||||
CategoryRelationship, Celebrity, Channel, Chapter, Child, ChildObjectA,
|
||||
Classroom, Company, Cover, CustomPk, CustomPkTag, Detail, DumbCategory,
|
||||
Eaten, Employment, ExtraInfo, Fan, Food, Identifier, Individual, Item, Job,
|
||||
JobResponsibilities, Join, LeafA, LeafB, LoopX, LoopZ, ManagedModel,
|
||||
Member, ModelA, ModelB, ModelC, ModelD, MyObject, NamedCategory, Node,
|
||||
Note, NullableName, Number, ObjectA, ObjectB, ObjectC, OneToOneCategory,
|
||||
Order, OrderItem, Page, Paragraph, Person, Plaything, PointerA, Program,
|
||||
ProxyCategory, ProxyObjectA, ProxyObjectB, Ranking, Related,
|
||||
RelatedIndividual, RelatedObject, Report, ReportComment, ReservedName,
|
||||
Responsibility, School, SharedConnection, SimpleCategory, SingleObject,
|
||||
SpecialCategory, Staff, StaffUser, Student, Tag, Task, Teacher,
|
||||
Ticket21203Child, Ticket21203Parent, Ticket23605A, Ticket23605B,
|
||||
Classroom, CommonMixedCaseForeignKeys, Company, Cover, CustomPk,
|
||||
CustomPkTag, Detail, DumbCategory, Eaten, Employment, ExtraInfo, Fan, Food,
|
||||
Identifier, Individual, Item, Job, JobResponsibilities, Join, LeafA, LeafB,
|
||||
LoopX, LoopZ, ManagedModel, Member, MixedCaseDbColumnCategoryItem,
|
||||
MixedCaseFieldCategoryItem, ModelA, ModelB, ModelC, ModelD, MyObject,
|
||||
NamedCategory, Node, Note, NullableName, Number, ObjectA, ObjectB, ObjectC,
|
||||
OneToOneCategory, Order, OrderItem, Page, Paragraph, Person, Plaything,
|
||||
PointerA, Program, ProxyCategory, ProxyObjectA, ProxyObjectB, Ranking,
|
||||
Related, RelatedIndividual, RelatedObject, Report, ReportComment,
|
||||
ReservedName, Responsibility, School, SharedConnection, SimpleCategory,
|
||||
SingleObject, SpecialCategory, Staff, StaffUser, Student, Tag, Task,
|
||||
Teacher, Ticket21203Child, Ticket21203Parent, Ticket23605A, Ticket23605B,
|
||||
Ticket23605C, TvChef, Valid, X,
|
||||
)
|
||||
|
||||
@ -1172,6 +1173,32 @@ class Queries1Tests(TestCase):
|
||||
with self.assertRaisesMessage(FieldError, msg):
|
||||
Tag.objects.filter(unknown_field__name='generic')
|
||||
|
||||
def test_common_mixed_case_foreign_keys(self):
|
||||
"""
|
||||
Valid query should be generated when fields fetched from joined tables
|
||||
include FKs whose names only differ by case.
|
||||
"""
|
||||
c1 = SimpleCategory.objects.create(name='c1')
|
||||
c2 = SimpleCategory.objects.create(name='c2')
|
||||
c3 = SimpleCategory.objects.create(name='c3')
|
||||
category = CategoryItem.objects.create(category=c1)
|
||||
mixed_case_field_category = MixedCaseFieldCategoryItem.objects.create(CaTeGoRy=c2)
|
||||
mixed_case_db_column_category = MixedCaseDbColumnCategoryItem.objects.create(category=c3)
|
||||
CommonMixedCaseForeignKeys.objects.create(
|
||||
category=category,
|
||||
mixed_case_field_category=mixed_case_field_category,
|
||||
mixed_case_db_column_category=mixed_case_db_column_category,
|
||||
)
|
||||
qs = CommonMixedCaseForeignKeys.objects.values(
|
||||
'category',
|
||||
'mixed_case_field_category',
|
||||
'mixed_case_db_column_category',
|
||||
'category__category',
|
||||
'mixed_case_field_category__CaTeGoRy',
|
||||
'mixed_case_db_column_category__category',
|
||||
)
|
||||
self.assertTrue(qs.first())
|
||||
|
||||
|
||||
class Queries2Tests(TestCase):
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user