-
Notifications
You must be signed in to change notification settings - Fork 463
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
Conversation
lib/ancestry/has_ancestry.rb
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
ancestry_was
for now to make tests passJust trying to make this pass for now. Not sure if it is actually working with rails 5.2