Skip to content
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

Closed
ehelms opened this issue Jan 29, 2015 · 7 comments
Closed

Last join wins when multiple joins in scope prior to search_for #120

ehelms opened this issue Jan 29, 2015 · 7 comments

Comments

@ehelms
Copy link

ehelms commented Jan 29, 2015

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.

@wvanbergen
Copy link
Owner

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?

@brocktimus
Copy link
Collaborator

Right now we're just usin ActiveRecord and very simple joins(:relationship) syntax. Then I think our filtering queries simply runs "against" the remote table name, rather than any aliases given to the join in question.

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.

@wvanbergen
Copy link
Owner

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.

@kbrock
Copy link

kbrock commented Mar 15, 2018

Has this been resolved?

Looks like @abenari may have fixed this problem in a7666e4 ( /via @ohadlevy )

@ares
Copy link
Collaborator

ares commented Mar 15, 2018

@ehelms, have you seen this recently? Thanks

@ehelms
Copy link
Author

ehelms commented Mar 15, 2018

Not recently no. Feel free to close.

@ares
Copy link
Collaborator

ares commented Mar 16, 2018

Thanks @kbrock and @ehelms, closing.

@ares ares closed this as completed Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants