Skip to content

Conversation

@mgrunberg
Copy link
Contributor

This commit (rails/rails@55ef531) introduced an additional order(:id) to assert_includes_and_joins_equal.
After that, some tests produce queries like ORDER BY authors.id, [authors].[id] ASC.
Other adapters are fine with this but SQL Server raises an error.

This PR doesn't try to deduplicate orders. That could be a complex task. Instead, it coerces the tests to ensure we don't duplicate order columns.
It also adds a test showing the current behavior.

@wpolicarpo
Copy link
Member

Just curious if you had a chance to investigate how difficult would be for the adapter be more proactive if we tried to remove duplication instead?

@mgrunberg
Copy link
Contributor Author

I thought about adding proactivity but I dropped the initiative without investigating how to implement it.

What I thought is that to cover all cases all orders need to be normalized (authors.id, [authors].id, etc are equal to [authors].[id] ASC), dealing with different structures (text vs arel nodes, etc). We need to deal with [authors].[id] ASC, [authors].[id] DESC. There are edge-cases I'm not sure yet how should be resolved: authors.id, authors.name, [authors].[id] DESC

With all that in mind, I chose to do the easiest thing to make tests pass 😅.

@wpolicarpo
Copy link
Member

Ok, thanks for the clarification. This is an already existing problem so let's move on and maybe we can come back to it later.

@wpolicarpo wpolicarpo merged commit c0f5f7b into rails-sqlserver:main Apr 21, 2021
@mgrunberg mgrunberg deleted the issues/yellowspot/rails-6-1/fix-order-list-not-unique branch January 3, 2022 17:32
lavika pushed a commit to lavika/activerecord-sqlserver-adapter that referenced this pull request Sep 26, 2023
…cified more than once in the order by list" (rails-sqlserver#894)

* add spec showing adapters behaviour

* coerce test avoiding duplicate columns in order list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants