yezyilomo / django-restql

Turn your API made with Django REST Framework(DRF) into a GraphQL like API.
https://yezyilomo.github.io/django-restql
MIT License
621 stars 43 forks source link

Fix patching nested object to its parent #301

Closed yezyilomo closed 2 years ago

yezyilomo commented 2 years ago
sommelon commented 2 years ago

Hey, thanks for the fix. One question: Won't saving the instance in a for loop cause unnecessary queries? Wouldn't it be better to first set the values and then save the instance only once? Or are there some other reasons for this?

yezyilomo commented 2 years ago

I thought about that too but the thing is instance.save should be called only when nested_obj is None which is not always the case when update_writable_foreignkey_related is called, so we'll still have unnecessary queries.

yezyilomo commented 2 years ago

@sommelon But I guess you could argue that the number of unnecessary queries we would have if we run instance.save outside the loop would be smaller than running inside the loop.

sommelon commented 2 years ago

I see what you mean. Maybe there could be a flag like needs_save or something that could be set when necessary and later decide whether to save or not.

yezyilomo commented 2 years ago

Having a flag seems great, though it will be executing repeatedly in a loop, but I don't think it will be as expensive as executing an unnecessary query, so let's settle for this for now.

sommelon commented 2 years ago

@yezyilomo great, thanks for the release!

yezyilomo commented 2 years ago

@yezyilomo great, thanks for the release!

You’re welcome