diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 1612921ec2ddb121f684c0dc6d12875351ff71ad..5a6f0d1e1bf524ff4d859b4301a88392a77b94a1 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -69,8 +69,11 @@ class Communication::Website::Post < ApplicationRecord scope :ordered, -> { order(published_at: :desc, created_at: :desc) } scope :recent, -> { order(published_at: :desc).limit(5) } scope :for_author, -> (author_id) { where(author_id: author_id) } - scope :for_category, -> (category_id) { } # TODO Sebou - scope :for_pinned, -> (pinned) { where(pinned: pinned == 'true') } # TODO Sebou + scope :for_category, -> (category_id) { + descendant_ids = Communication::Website::Category.find_by(id: category_id)&.descendants&.map(&:id) || [] + joins(:categories).where(communication_website_categories: { id: [category_id, descendant_ids].flatten }).distinct + } + scope :for_pinned, -> (pinned) { where(pinned: pinned == 'true') } scope :for_search_term, -> (term) { where(" unaccent(communication_website_posts.description) ILIKE unaccent(:term) OR