Fix query with has_and_belongs