Filter through relations working on mysql