summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/project.rb9
-rw-r--r--lib/redmine/nested_set/traversing.rb8
2 files changed, 8 insertions, 9 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 77f52737f..90ca7cbe4 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -696,15 +696,6 @@ class Project < ActiveRecord::Base
safe_attributes 'inherit_members',
:if => lambda {|project, user| project.parent.nil? || project.parent.visible?(user)}
- # Returns an array of projects that are in this project's hierarchy
- #
- # Example: parents, children, siblings
- def hierarchy
- parents = project.self_and_ancestors || []
- descendants = project.descendants || []
- project_hierarchy = parents | descendants # Set union
- end
-
# Returns an auto-generated project identifier based on the last identifier used
def self.next_identifier
p = Project.order('id DESC').first
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