]> source.dussan.org Git - redmine.git/commitdiff
Moved Project#hierarchy to NestedSet::Traversing.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 7 Jan 2015 20:37:06 +0000 (20:37 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 7 Jan 2015 20:37:06 +0000 (20:37 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13843 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
lib/redmine/nested_set/traversing.rb

index 77f52737ffab9e0c31c8ffa9c2f90939d4a55d24..90ca7cbe4f5daed0692a57a0c16c04c3e49ffe91 100644 (file)
@@ -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
index f1684c00b59115389cd51d5dd6e1eb221026144a..5c58f60d687a8396cb0492e2227de9d520a03898 100644 (file)
@@ -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