Files collection has no parent?

I am trying to use the find function on a Files-collection obtained from a blueprint-field. But apparently it doesn’t have a parent set, meaning it is not able to do any ‘find’ operations since those all use the parent-id as part of their search querry.

Curious is that iteration, and first and last functions still work.

Is this intended behavior or a bug? or am I missing something? (I was trying to detect if a specific file existed in the file-collection based on a filename).

Could you please provide your code and blueprint setup of the files field for testing?

this field is on the same ‘myPage’ as the icons in the query are

label: test
type: files
layout: cards
required: true
size: tiny
query: site.drafts.find('myPage')
image:
  cover: true
  ratio: 1/1

in a snippet

$my_page = site()->drafts()->find('myPage');
$files = $my_page->files()->toFiles();

# $files->parent(); // returns NULL
# $files->find('someFile.txt'); // crashes with NLPTR at findById because it tries to use the parent-id

It crashes in the findById() function from the Files class.

Yes, you are right, that doesn’t seem to work.

However,

This code doesn’t make sense, since files() would catch all files from the page, not from a field, and calling toFiles() on it then doesn’t make sense.

yes, the snippets are semi-pseudocode (for brevity). I haven’t tested it with these exact names, so it might have caused problems indeed.

I currently use a loop as a workaround (quit bluky and ugly-lookin, and potentially less efficient as I saw the ‘find’ methods use array-pointer access). But I assume this should have worked (given I use correct names)? In other words, this is a confirmed bug?

Probably, definitely worth looking into.

Alright, I will flag the snippet for future reference may there be any changes, thanks for the response

If you only need to find a single element, you could use findBy() instead of find. For multiple files, use filterBy() instead.

seems to work. So that will at least be a one-liner. Thanks for the hint!