Skip to content

Column order issue on select statement - task - https://app.clickup.c…#17

Open
Girish B (Girish2402) wants to merge 2 commits intomasterfrom
column_order_issue
Open

Column order issue on select statement - task - https://app.clickup.c…#17
Girish B (Girish2402) wants to merge 2 commits intomasterfrom
column_order_issue

Conversation

@Girish2402
Copy link
Copy Markdown
Collaborator

Description

find_by_sql doesn't preserve the column order.
reference link - https://stackoverflow.com/questions/209558/column-order-of-results-from-rails-activerecord-find-by-sql-call

Clickup Story

https://app.clickup.com/t/1c5cry4

Deployment Details

Standard process

Reminders

  • All scenarios are tested
  • Test cases added if required
  • Schema and migrations are updated
  • A11y guidelines are followed WCAG

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query = build_query()
@results = @model.find_by_sql([query, @bind_variables]) # Execute Sql Query
query = to_sql
@results = @model.connection.select_all(query).as_json # Execute Sql Query
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Girish B (@Girish2402) Do you have any test result to prove that it is not changing output, In my understanding select_all returns array of hash or json and find_by_sql returns model objects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Girish B (@Girish2402) Can you also explain why do you need this change? what is the use case?

Copy link
Copy Markdown
Collaborator Author

@Girish2402 Girish B (Girish2402) Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vishal Zambre (@vishalzambre)
We rely on the order that we pass on the select statements in query for CSV column order but it's not getting the same order.
Task - https://app.clickup.com/t/1c5cry4

Copy link
Copy Markdown
Collaborator Author

@Girish2402 Girish B (Girish2402) Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Vishal Zambre (@vishalzambre) Nilesh Navale (@NileshN)

I add test cases for association(include) but its fails.
Association is failing for these changes.
https://github.com/patterninc/query_helper#associations
Do not merge changes.

Test results:
Failure/Error: ActiveRecord::Associations::Preloader.new.preload(payload, associations)

 NoMethodError:
   undefined method `_reflect_on_association' for Hash:Class

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.

3 participants