[FIX] Query should be rewritten to use orm as function fields need to be updated