Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Join to searchable model with nested associations not including tables #125
In Foreman, we hit an issue in the following scenario:
We then want to list reports for hosts that match a certain hostgroup, so:
This is equivalent to:
But the resulting joined SQL query doesn't include the hostgroups table, so throws an error:
It seems the right way to do this in Rails is:
I've sort of managed to work around it by calling ScopedSearch::QueryBuilder.build_query directly and then generating an AR query with the right sequence as shown above, but it would be good to have some help building join queries in scoped_search itself - if this is the case, and I'm not missing something blindingly obvious.
In our case the scoped search queries could be querying a variety of objects associated to host depending on user configuration, so hardcoding this isn't an option. As a workaround, it's possible to make an inefficient query with IDs, but this was very slow with large numbers of hosts.
Here's a small application and unit test demonstrating it: https://github.com/domcleal/ss_join_search_issue (scoped_search 3.2.0, Rails 4.2.0, sqlite 3.8.8, Ruby 2.0.0).
Diving even deeper into this, looks like the issue may actually be in Rails ignoring