diff options
author | David Wobrock <david.wobrock@gmail.com> | 2023-03-06 21:17:58 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-14 08:32:17 +0100 |
commit | de0c7744be93800b2239eb061a2d8f7c669c05a8 (patch) | |
tree | 9de36d5d64eb184974257b0bc3d4def893ef2eb1 /tests/db_functions | |
parent | 254ad2e3450d8175170914f06af8358d2becc35b (diff) | |
download | django-de0c7744be93800b2239eb061a2d8f7c669c05a8.tar.gz |
Refs #28329 -- Fixed Cast() with ForeignKey to integer fields on MySQL.
Diffstat (limited to 'tests/db_functions')
-rw-r--r-- | tests/db_functions/comparison/test_cast.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/db_functions/comparison/test_cast.py b/tests/db_functions/comparison/test_cast.py index afb6b473b9..80375cc389 100644 --- a/tests/db_functions/comparison/test_cast.py +++ b/tests/db_functions/comparison/test_cast.py @@ -76,6 +76,15 @@ class CastTests(TestCase): numbers = Author.objects.annotate(cast_int=Cast("alias", field_class())) 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): duration = datetime.timedelta(days=1, seconds=2, microseconds=3) DTModel.objects.create(duration=duration) |