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

Fix columns error when using join queries #471

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

Conversation

addbrick
Copy link

When using the ActiveRecordEnumerator, Update validation of columns in active record enumerator to allow for Arel and String values.

This fixes a an issue where using join queries kept running into the columns error and passing in columns with . values would cause errors when the query was executed.

Example

# This would produce an error due to no "fully-qualified" columns
enumerator_builder.active_record_on_records(
  User.join(:memberships).where(memberships: { role: 'host' }),
  cursor: cursor,
  batch_size: 1
)

# If you add a columns field with symbols, you get the no fully-qualified columns error again
enumerator_builder.active_record_on_records(
  User.join(:memberships).where(memberships: { role: 'host' }),
  cursor: cursor,
  batch_size: 1,
  columns: [:id]
)

# If you attempted to add a string value with a fully-qualified column, you get a sql error when executing the query
enumerator_builder.active_record_on_records(
  User.join(:memberships).where(memberships: { role: 'host' }),
  cursor: cursor,
  batch_size: 1
  cursor: ['users.id']
)
# Produces a double table name in the sql query
`ORDER BY "users"."users.id"`

The change this PR is to only raise the error if the columns are not all Arel::Attributes::Attribute or string with no . in it. When you call to_s on a Arel::Attributes::Attribute it becomes fully qualified.

I believe this condition just missed getting updated with the move to convert all columns to Arel attributes for the ActiveRecordEnumerator, in this PR #456 from earlier this year.

… Arel and String values

This fixes a an issue where using join queries kept running into the columns error.
@Mangara
Copy link
Contributor

Mangara commented Mar 30, 2024

Thanks for fixing this! Could you add a test for this case?

We also need you to sign the CLA before we can merge it.

@addbrick
Copy link
Author

Just an update, we ended up not needing this right away so it has become a lower priority. It is on my list to add tests and get this pr merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants