From 8b6d3c76451d4ece5fd829d0e2d96a00aa19122d Mon Sep 17 00:00:00 2001 From: erdgeist Date: Wed, 22 Jul 2026 20:44:34 +0200 Subject: Add attached nodes subsection in assets#show and thumbnail in nodes#create --- app/models/asset.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/models') diff --git a/app/models/asset.rb b/app/models/asset.rb index ba9c2f0..73970e2 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -31,4 +31,13 @@ class Asset < ApplicationRecord def show_credit? image? && has_credit? end + + # Nodes whose current lifecycle rows (head, draft or autosave) carry + # this asset. Historical revisions also hold RelatedAsset rows; they + # are excluded by construction here, since nothing points at them. + def attached_nodes + page_ids = related_assets.select(:page_id) + Node.where("head_id IN (:ids) OR draft_id IN (:ids) OR autosave_id IN (:ids)", + :ids => page_ids).distinct + end end -- cgit v1.3