collectiveidea / awesome_nested_set

An awesome replacement for acts_as_nested_set and better_nested_set.
MIT License
2.39k stars 492 forks source link

Order By column name now no longer includes the table name when using scope ".roots" #469

Closed bli closed 2 years ago

bli commented 2 years ago

Let's say Answer is an ActiveRecord with acts_as_nested_set, try this in console:

Answer.roots.to_sql "SELECT \"answers\".* FROM \"answers\" WHERE \"answers\".\"parent_id\" IS NULL ORDER BY lft"

Note that the generated ORDER BY clause is not referencing the table name "answers"

In 3.4.0 and before, it did include the table name so that there won't be ambiguity when there are multiple tables with the same column in the query.

This is the line that is causing the issue: https://github.com/collectiveidea/awesome_nested_set/blob/7387a479ee9b82b390191e1336da150d0063d305/lib/awesome_nested_set/model.rb#L101

That seems to be introduced in this PR: https://github.com/collectiveidea/awesome_nested_set/pull/451/files/fa99eee57e2c8e380ed71e1d2324b0993ad809b8#diff-ff6b9b918954b07e491e706e57072b078caa30cc7e439587ed31a5c147183eb0

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

bli commented 12 months ago

For those who have the same issue, to avoid this issue, instead of using the default configuration, you can explicitly specify the order column like this below: acts_as_nested_set order_column: :lft