How to filter SQL results in a has-many-through relation How to filter SQL results in a has-many-through relation mysql mysql