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

Add .on method to Arel::Node::TableAlias for subquery alias joins #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add .on method to Arel::Node::TableAlias for subquery alias joins #103

wants to merge 1 commit into from

Conversation

CodingAnarchy
Copy link

I was running into a situation on a production app where we were doing a join on a subquery, and we were getting an undefined method 'on' for Arel::Node::TableAlias with the following structure:

# Query 1
subquery = Foo.joins(:bar).select('DISTINCT ON (foo.id) foo_id, bar.timestamp').order('foo.id, bar.timestamp DESC')

# Query 2
Foo.distinct.joining{ |foo| subquery.as('foo_subquery').on { foo_id == foo.id }.outer }

I added this patch, and that allowed the second query to proceed and generate the correct SQL to hit the database. I thought it would be helpful to create a pull request, especially as it appears that this might be what was trying to be done in #46?

@coveralls
Copy link

coveralls commented Jun 21, 2019

Coverage Status

Coverage decreased (-3.9%) to 95.126% when pulling 7f5103c on CodingAnarchy:table-alias-on into a71a462 on rzane:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.4%) to 94.605% when pulling 7f5103c on CodingAnarchy:table-alias-on into a71a462 on rzane:master.

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

Successfully merging this pull request may close these issues.

2 participants