From 8bb6f2809790d36d0613a532a8f627c7d7531b78 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <arnaud.levy@noesya.coop>
Date: Tue, 19 Nov 2024 12:08:55 +0100
Subject: [PATCH] =?UTF-8?q?R=C3=A9paration=20de=20l'arbre=20localis=C3=A9?=
 =?UTF-8?q?=20(#2435)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/models/concerns/as_localized_tree.rb | 25 ++++++++++++------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/app/models/concerns/as_localized_tree.rb b/app/models/concerns/as_localized_tree.rb
index 53b3d7dd1..f19f6b1ac 100644
--- a/app/models/concerns/as_localized_tree.rb
+++ b/app/models/concerns/as_localized_tree.rb
@@ -44,8 +44,7 @@ module AsLocalizedTree
   end
 
   def ancestors
-    has_parent? ? parent.ancestors.push(parent)
-                : []
+    has_parent? ? parent.ancestors.push(parent) : []
   end
 
   def ancestors_and_self
@@ -53,8 +52,7 @@ module AsLocalizedTree
   end
 
   def descendants
-    has_children? ? children.ordered.map { |child| [child, child.descendants].flatten }.flatten
-                  : []
+    has_children? ? descendants_flattened : []
   end
 
   def descendants_and_self
@@ -70,21 +68,22 @@ module AsLocalizedTree
   def parent_siblings
     self.class.about_class
               .unscoped
-              .where(
-                parent_id: about.parent_id,
-                university: university
-              )
+              .where(parent_id: about.parent_id, university: university)
               .where.not(id: about.id)
-              .ordered
+              .ordered(language)
   end
 
   def localizations_for(abouts)
     about_ids = abouts.pluck(:id)
     self.class.unscoped
-              .where(
-                language_id: language_id,
-                about_id: about_ids
-              )
+              .where(language_id: language_id, about_id: about_ids)
+  end
+
+  # Beaucoup trop semblable à WithTree
+  def descendants_flattened
+    children.ordered(language).map { 
+      |child| [child, child.descendants] 
+    }.flatten
   end
 
 end
-- 
GitLab