diff --git a/docs/models.md b/docs/models.md index fc29f6e..dfc8324 100644 --- a/docs/models.md +++ b/docs/models.md @@ -359,8 +359,8 @@ But you can specify the `follow=True` parameter to traverse through nested model So if you have a diamond or circular relations types you need to perform the updates in a manual way. ```python - # in example like this the second Street (coming from Company) won't be save_related, so Whatever won't be updated - Street -> District -> City -> Companies -> Street -> Whatever + # in example like this the second Street (coming from City) won't be save_related, so ZipCode won't be updated + Street -> District -> City -> Street -> ZipCode ``` ## Internals diff --git a/ormar/__init__.py b/ormar/__init__.py index 03476f4..7f9e9e2 100644 --- a/ormar/__init__.py +++ b/ormar/__init__.py @@ -30,7 +30,7 @@ class UndefinedType: # pragma no cover Undefined = UndefinedType() -__version__ = "0.4.4" +__version__ = "0.5.0" __all__ = [ "Integer", "BigInteger", diff --git a/ormar/models/model.py b/ormar/models/model.py index aeb63c3..fb5c295 100644 --- a/ormar/models/model.py +++ b/ormar/models/model.py @@ -234,7 +234,7 @@ class Model(NewBaseModel): @staticmethod async def _update_and_follow( - rel: "Model", follow: bool, visited: Set, update_count: int + rel: T, follow: bool, visited: Set, update_count: int ) -> Tuple[int, Set]: if follow and rel.__class__ not in visited: update_count = await rel.save_related( diff --git a/tests/test_save_related.py b/tests/test_save_related.py index 6cfe108..967ef1c 100644 --- a/tests/test_save_related.py +++ b/tests/test_save_related.py @@ -161,15 +161,27 @@ async def test_saving_reversed_relation(): assert hq.companies[0].saved assert hq.companies[1].saved + hq = await HQ.objects.select_related( + ["companies", "companies__hq__nicks"] + ).get(name="Main") + hq.companies[0].hq.nicks[0].name = "Sub" + assert not hq.companies[0].hq.nicks[0].saved + await hq.save_related(follow=True) + assert not hq.companies[0].hq.nicks[0].saved + @pytest.mark.asyncio async def test_saving_nested(): async with database: async with database.transaction(force_rollback=True): - level = await CringeLevel.objects.create(name='High') - level2 = await CringeLevel.objects.create(name='Low') - nick1 = await NickNames.objects.create(name="BazingaO", is_lame=False, level=level) - nick2 = await NickNames.objects.create(name="Bazinga20", is_lame=True, level=level2) + level = await CringeLevel.objects.create(name="High") + level2 = await CringeLevel.objects.create(name="Low") + nick1 = await NickNames.objects.create( + name="BazingaO", is_lame=False, level=level + ) + nick2 = await NickNames.objects.create( + name="Bazinga20", is_lame=True, level=level2 + ) hq = await HQ.objects.create(name="Main") assert hq.saved