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

Improve performance of self_and_descendants #122

Merged
merged 2 commits into from
Mar 16, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/awesome_nested_set/awesome_nested_set.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ def level
# Returns a set of itself and all of its nested children # Returns a set of itself and all of its nested children
def self_and_descendants def self_and_descendants
nested_set_scope.where([ nested_set_scope.where([
"#{self.class.quoted_table_name}.#{quoted_left_column_name} >= ? AND #{self.class.quoted_table_name}.#{quoted_right_column_name} <= ?", left, right "#{self.class.quoted_table_name}.#{quoted_left_column_name} >= ? AND #{self.class.quoted_table_name}.#{quoted_left_column_name} < ?", left, right
# using _left_ for both sides here lets us benefit from an index on that column if one exists
]) ])
end end


Expand Down