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).
$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.
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?