From c57ee2e632718fb5c1b93470ce3b47eeaaa074f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Thu, 28 Apr 2022 12:41:16 +0200 Subject: [PATCH] #342 --- app/models/communication/block/template/post.rb | 7 ++++++- app/models/university/with_communication.rb | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index fb5b7d9e3..aa4143e90 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -33,7 +33,12 @@ class Communication::Block::Template::Post < Communication::Block::Template def selected_posts_category quantity = data['posts_quantity'] || 3 - category.posts.ordered.limit(quantity) + category_ids = [category.id, category.descendants.map(&:id)].flatten + university.communication_website_posts.joins(:categories) + .where(categories: { id: category_ids }) + .distinct + .ordered + .limit(quantity) end def selected_posts_selection diff --git a/app/models/university/with_communication.rb b/app/models/university/with_communication.rb index c43441eb8..5dd2a35ba 100644 --- a/app/models/university/with_communication.rb +++ b/app/models/university/with_communication.rb @@ -12,6 +12,10 @@ module University::WithCommunication dependent: :destroy alias_attribute :websites, :communication_websites + has_many :communication_website_posts, + class_name: 'Communication::Website::Post', + dependent: :destroy + has_many :communication_blocks, class_name: 'Communication::Block', dependent: :destroy -- GitLab