diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/nested_set/traversing.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/redmine/nested_set/traversing.rb b/lib/redmine/nested_set/traversing.rb index f1684c00b..5c58f60d6 100644 --- a/lib/redmine/nested_set/traversing.rb +++ b/lib/redmine/nested_set/traversing.rb @@ -111,6 +111,14 @@ module Redmine def is_or_is_descendant_of?(other) other == self || is_descendant_of?(other) end + + # Returns the ancestors, the element and its descendants + def hierarchy + nested_set_scope.where( + "#{self.class.table_name}.lft >= :lft AND #{self.class.table_name}.rgt <= :rgt" + + " OR #{self.class.table_name}.lft < :lft AND #{self.class.table_name}.rgt > :rgt", + {:lft => lft, :rgt => rgt}) + end end end end |