get_record_by_id for orphan files

I've discovered that:

$file = get_record_by_id("file", $fileid)

works ONLY for files that belong to items that are referenced to in omeka_items table, i.e. those files whose item_id has a corresponding id in omeka_items.

I am sure this is done for a good reason, but in my worfklow I need to create file objects based on ids for "orphaned" files, i.e. those files who's item no longer exists. How can I do that?

Or to put the same question slightly differently: if I start with:

$sql = "select * from omeka_files where item_id not in (select id from omeka_items)";
$result = get_db()->fetchAll($sql);

how can I covert my database rows into proper file objects (so that I can do file_markup($file) with them... ?

All best,

fetchObjects() on the File table object is the method you're looking for.

$files = get_db()->getTable('File')->fetchObjects($sql);

Note that the code in lots of places is built around the assumption that there are no "orphan" files. Permission handling and several other things for Files inherit from their parent Item.

That's great, John. Thanks a lot!