Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'dangerous errors' when using in Rails 5.2 #384

Merged
merged 4 commits into from
Apr 18, 2018

Conversation

kbrock
Copy link
Collaborator

@kbrock kbrock commented Apr 17, 2018

Just trying to make this pass for now. Not sure if it is actually working with rails 5.2

@coveralls
Copy link

coveralls commented Apr 17, 2018

Coverage Status

Coverage decreased (-0.02%) to 98.05% when pulling 4fd4b7c on kbrock:deprecations into 8111e08 on stefankroes:master.

@@ -46,7 +46,7 @@ def has_ancestry options = {}
scope :siblings_of, lambda { |object| where(sibling_conditions(object)) }
scope :ordered_by_ancestry, Proc.new { |order|
if %w(mysql mysql2 sqlite sqlite3 postgresql).include?(connection.adapter_name.downcase) && ActiveRecord::VERSION::MAJOR >= 5
reorder("coalesce(#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)}, '')", order)
reorder(Arel.sql("coalesce(#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)}, '')"), order)
else
reorder("(CASE WHEN #{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)} IS NULL THEN 0 ELSE 1 END), #{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)}", order)
Copy link

@mu-is-too-short mu-is-too-short Apr 17, 2018

Choose a reason for hiding this comment

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

You might want to include an Arel.sql call in the else branch too.

Copy link
Collaborator Author

@kbrock kbrock Apr 17, 2018

Choose a reason for hiding this comment

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

thanks - thought it is specifically for AR < 5 && non pg.

will see if it passes rails 3.x with Arel

Choose a reason for hiding this comment

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

It'll go into the CASE version for any driver that isn't MySQL, SQLite, or PostgreSQL regardless of the ActiveRecord major version.

That said, that's an odd looking test to me, the AR version shouldn't matter and I'm pretty sure every database these days has a coalesce function. But maybe I'm wrong and this is just bike-shedding anyway

@kbrock kbrock merged commit 8b84070 into stefankroes:master Apr 18, 2018
@kbrock kbrock deleted the deprecations branch April 18, 2018 00:53
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.

4 participants