Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/query_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def view_query
end

def execute_query
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
Contributor

Choose a reason for hiding this comment

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

@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
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Collaborator Author

@Girish2402 Girish2402 Oct 19, 2021

Choose a reason for hiding this comment

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

@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
Collaborator Author

@Girish2402 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 @vishalzambre @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

@results = @results.first if @single_record # Return a single result if requested

determine_count()
Expand Down