I have a query with multiple JOINs.
At the moment I get a result with all the columns from all the tables. And some of the columns have identical names because that's how it's in my database. How can I select the columns to return and adjust their names in the result set?
I've tried:
result = MyModel1.join(:table2, id: :table2_id)
if condition1
result = result.join(.....).where(.....)
end
if condition2
result = result.join(.....).where(.....)
end
# and so on....
result
And if I'm doing this:
result.select([Sequel[:model1][:column1], Sequel[:model2][:column2]])
I end up with this after I convert it to json:
[{"row":["column1_value1","column1_value11"]},{"row":["column1_value2","column1_value22"]},{"row":["column1_value3","column1_value33"]}]
What's the "row"? How to get rid of it? How to add the names of the columns and change the structure of that json response so it looks proper?
I want something like this:
[
{"column1": "column1_value1", "column2" "column1_value11"},
{"column1": "column1_value2", "column2" "column1_value22"},
{"column1": "column1_value3", "column2" "column1_value33"}
]