diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-22 20:44:34 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-22 20:44:34 +0200 |
| commit | 8b6d3c76451d4ece5fd829d0e2d96a00aa19122d (patch) | |
| tree | 9195c97479e42b822931bee9bad037dac8600af0 /app/models | |
| parent | b78a91f158f90343d49a252fc332680108eba18d (diff) | |
Add attached nodes subsection in assets#show and thumbnail in nodes#create
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/asset.rb | 9 |
1 files changed, 9 insertions, 0 deletions
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 | |||
| 31 | def show_credit? | 31 | def show_credit? |
| 32 | image? && has_credit? | 32 | image? && has_credit? |
| 33 | end | 33 | end |
| 34 | |||
| 35 | # Nodes whose current lifecycle rows (head, draft or autosave) carry | ||
| 36 | # this asset. Historical revisions also hold RelatedAsset rows; they | ||
| 37 | # are excluded by construction here, since nothing points at them. | ||
| 38 | def attached_nodes | ||
| 39 | page_ids = related_assets.select(:page_id) | ||
| 40 | Node.where("head_id IN (:ids) OR draft_id IN (:ids) OR autosave_id IN (:ids)", | ||
| 41 | :ids => page_ids).distinct | ||
| 42 | end | ||
| 34 | end | 43 | end |
