mirror of
https://github.com/django/django.git
synced 2025-03-27 01:30:46 +00:00
Refs #28329 -- Fixed Cast() with ForeignKey to integer fields on MySQL.
This commit is contained in:
parent
254ad2e345
commit
de0c7744be
@ -1162,6 +1162,9 @@ class ForeignKey(ForeignObject):
|
|||||||
def db_type(self, connection):
|
def db_type(self, connection):
|
||||||
return self.target_field.rel_db_type(connection=connection)
|
return self.target_field.rel_db_type(connection=connection)
|
||||||
|
|
||||||
|
def cast_db_type(self, connection):
|
||||||
|
return self.target_field.cast_db_type(connection=connection)
|
||||||
|
|
||||||
def db_parameters(self, connection):
|
def db_parameters(self, connection):
|
||||||
target_db_parameters = self.target_field.db_parameters(connection)
|
target_db_parameters = self.target_field.db_parameters(connection)
|
||||||
return {
|
return {
|
||||||
|
@ -76,6 +76,15 @@ class CastTests(TestCase):
|
|||||||
numbers = Author.objects.annotate(cast_int=Cast("alias", field_class()))
|
numbers = Author.objects.annotate(cast_int=Cast("alias", field_class()))
|
||||||
self.assertEqual(numbers.get().cast_int, 1)
|
self.assertEqual(numbers.get().cast_int, 1)
|
||||||
|
|
||||||
|
def test_cast_to_integer_foreign_key(self):
|
||||||
|
numbers = Author.objects.annotate(
|
||||||
|
cast_fk=Cast(
|
||||||
|
models.Value("0"),
|
||||||
|
models.ForeignKey(Author, on_delete=models.SET_NULL),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.assertEqual(numbers.get().cast_fk, 0)
|
||||||
|
|
||||||
def test_cast_to_duration(self):
|
def test_cast_to_duration(self):
|
||||||
duration = datetime.timedelta(days=1, seconds=2, microseconds=3)
|
duration = datetime.timedelta(days=1, seconds=2, microseconds=3)
|
||||||
DTModel.objects.create(duration=duration)
|
DTModel.objects.create(duration=duration)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user