diff --git a/CHANGELOG.md b/CHANGELOG.md index c9862b12..b4d09e06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added ### Changed +- Handle bulk creation when using reverse related name ### Removed diff --git a/tests/generic/models.py b/tests/generic/models.py index 834e20ef..789c7e7a 100755 --- a/tests/generic/models.py +++ b/tests/generic/models.py @@ -483,11 +483,3 @@ class ModelWithAutoNowFields(models.Model): sent_date = models.DateTimeField() created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) - - -class House(models.Model): - pass - - -class HouseDetail(models.Model): - houses = models.ManyToManyField(House, blank=True) diff --git a/tests/test_baker.py b/tests/test_baker.py index 07917765..e0c48744 100644 --- a/tests/test_baker.py +++ b/tests/test_baker.py @@ -1069,11 +1069,17 @@ def test_create(self): assert list(c1.students.all()) == list(c2.students.all()) == [person] def test_make_should_create_objects_using_reverse_name(self): - detail = baker.make(models.HouseDetail) - houses = baker.make( - models.House, housedetail_set=[detail], _quantity=20, _bulk_create=True - ) - assert houses[0].housedetail_set.count() == 1 + classroom = baker.make(models.Classroom) + + with self.assertNumQueries(21): + students = baker.make( + models.Person, + classroom_set=[classroom], + _quantity=10, + _bulk_create=True, + ) + + assert students[0].classroom_set.count() == 1 class TestBakerSeeded: