How to query related submissions for an asset? #1764
-
Hi @engram-design, we’re trying to do a cleanup job of all the duplicate assets created before this bug fix #1729 was deployed. The idea was to run through all the assets on the volume, check if they are related to a submission, and if not, delete the asset. However, I’m unable to figure out the query to get this to work. Here’s an example:
Any suggestions for the right query to figure out submissions related to an asset (both directly and via a group field)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Are your File Upload fields in a Group or Repeater field? If so, that'll be tricky as each block for those fields is an element on it's own - just like Matrix and Super Table. That means that the relationship is tied between the asset and the Group/Repeater Block element. However, using craft.formie.submissions.relatedTo({ element: 19694 }).exists() Works for me on top-level fields. For nested fields, you can only really do that in PHP. \verbb\formie\elements\NestedFieldRow::find()->relatedTo(['element' => 19694])->exists(); But you'd want to be careful with that, as it's just matching against a "block", not a block and submission. |
Beta Was this translation helpful? Give feedback.
Are your File Upload fields in a Group or Repeater field? If so, that'll be tricky as each block for those fields is an element on it's own - just like Matrix and Super Table. That means that the relationship is tied between the asset and the Group/Repeater Block element.
However, using
relatedTo
for non Group/Repeater fields (so File Uploads at the top level of the form) should be fine. But you're going to run into issues using thefield
reference, because these are Formie fields, and not Craft fields.Works for me on top-level fields. For nested fields, you can only really do that in PHP.
\verbb\formie\elements\NestedFieldRow…