Filter through relations working on postgres