You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, it's not failing due to my select clause above. Instead, it's a problem with this code in rails_cursor_pagination/paginator.rb:
if custom_order_field? && [email protected]_values.include?(@order_field)
relation = relation.select(@order_field)
end
which results in this SQL being generated:
SELECT pizzas.*, pizza_users.preference AS preference, preference
FROM "pizzas" INNER JOIN "pizza_users" ON "pizza_users"."pizza_id" = "pizzas"."id"
ORDER BY "preference" ASC, "pizzas"."id" ASC LIMIT $2
Even though I already had "preference" defined using "AS" - the code above @relation.select_values.include?(@order_field) is doing an overly simple analysis of selected fields and then appends a non-existent field to my list of fields.
How to solve? Here are my thoughts:
Honestly I don't feel like rails_cursor_pagination should be modifying my select clause at all. I'd rather have an exception raised and fix my query to select the appropriate column. This is my preferred solution b/c there are so many possible ways to muck up queries, especially complex ones. But, this is a potentially breaking change for people who depend on that behavior.
You could improve the logic of deciding whether a selected column is already in the query. Perhaps if that column name text appears anywhere in the select clause, it shouldn't be appended. Or at a minimum it should understand that something AS column_name means that column_name is selected.
You could allow disabling this behavior via a preference flag. You could even make this optional initially, but switch to the default in the future with a breaking change release warning. (if you agree with my thoughts in (1))
Either way, without a bugfix/code modification I can't think of any way to workaround this issue.
The text was updated successfully, but these errors were encountered:
I want to paginate a joined table and sort on a column in the join table:
However, if you do this:
It will fail because order_field_value doesn't exist because it can't call
pizza['pizza_users.preference']
since preference is on the join table.Ah hah - I know the solution, I'll just select the preference column so that
pizza['preference']
will work, like so:But that will fail with:
However, it's not failing due to my select clause above. Instead, it's a problem with this code in rails_cursor_pagination/paginator.rb:
which results in this SQL being generated:
Even though I already had "preference" defined using "AS" - the code above
@relation.select_values.include?(@order_field)
is doing an overly simple analysis of selected fields and then appends a non-existent field to my list of fields.How to solve? Here are my thoughts:
something AS column_name
means thatcolumn_name
is selected.Either way, without a bugfix/code modification I can't think of any way to workaround this issue.
The text was updated successfully, but these errors were encountered: