Add a subselect query when the search is using a has_many relation
Add failing test for the has_many through case