-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Last join wins when multiple joins in scope prior to search_for #120
Comments
We rely on ActiveRecord / Arel to generate the JOINs (and their aliases). I am not sure if AR offers eays to easily ensure that join aliases are unique? |
Right now we're just usin ActiveRecord and very simple The problem comes about when you join multiple times to a single table. ActiveRecord has different behaviour in how it names the first time you join to a table and every other time. Lots more details in #94 even with code + SQL examples. To my knowledge we can't introspect the aliases which have been given. So we likely have to manually construct LEFT JOINs for all our stuff in addition to changing all our filters to using the alias we've constructed for that specific LEFT JOIN. If we can introspect the aliases given to each specific joins that would also work, but I haven't been able to see anyway its possible. |
I feel we cannot really address this without rewriting the query engine to be less dependent on ActiveRecord. That's a big amount of work, and I don't see it happening anytime soon. |
@ehelms, have you seen this recently? Thanks |
Not recently no. Feel free to close. |
We found an issue where if we build up a query that contains multiple of the same join, and then call search_for, the last join wins. If you are curious, we chain scopes together in our API depending upon what the user supplies as parameters to provide data subsets (https://github.com/Katello/katello/blob/master/app/controllers/katello/concerns/api/v2/repository_db_content_controller.rb#L50). Some of the queries we apply call the same join but with different data (https://github.com/Katello/katello/blob/master/app/models/katello/glue/pulp/pulp_content_unit.rb#L40). When we build a query that contains 2 or more of these, and then call
query.search_for
we find that the last joins data is what the search_for criteria is applied to. For now, we are working around this by doing a `search_for('foo').merge(query)'; however, this could easily be missed throughout the application and the wrong data presented to users.The text was updated successfully, but these errors were encountered: