ocadotechnology / codeforlife-portal-backend

Other
0 stars 15 forks source link

transfer class #310

Closed SKairinos closed 6 months ago

SKairinos commented 6 months ago

This change is Reviewable

SKairinos commented 6 months ago

backend/api/serializers/klass.py line 35 at r1 (raw file):

Previously, faucomte97 (Florian Aucomte) wrote…
Shall we do just `school` instead of `school_id`?

Generally speaking, it's more efficient to compare 2 related objects by their iIDs as you avoid fetching the related objects from the db. Also it does the same equality comparison under the hood anyway so it's logically the same check.

This will not call the db to fetch the school objects and check the ids

value.school_id != user.teacher.school_id

This call the db to fetch the 2 school objects (so 2 db calls) and then check the ids (under the hood it's doing value.school.id != user.teacher.school.id)

value.school != user.teacher.school