Filebase
Filebase copied to clipboard
Feature Request: Include ID in results() array (optionally?)
When you use resultDocuments() you can get use getID() to get the ID. But when you use the lighter-weight and default results() there seems to be no way to also return the ID with the records in the array.
To answer this one. You can call results()
for both. results(true)
(by default) will return just the data itself, meaning no way to have methods of calling ID. If you use results(false)
this would give you all the documents and their methods. Which is the same as calling resultDocuments()
But that's by preference. If you want the getId()
then use resultDocuments()
since all the document methods will be available. The reason ID is not inside the array of data is to prevent messing with any data you have stored on the document.
Unfortunately, there would be no way to use getId()
with results()
for just the array of data.
No, I get that... but why not an associative array where the keys are the IDs?
I would think it’s commonly desired to have the id available, but so much slower and resource intensive to have to iterate through the objects and gather the IDs and then flatten to an array and insert the the IDs.
Alternatively, I figured I could store the ID inside the document, but that seemed silly since the file name is already the ID. I guess that’s what I’ll do though for now.
@instanttim Actually, you do make a good point on the associative array keys. It would make sense to have the keys as document ids this way they can always be referenced. I'm going to add that to the list.
Guess it didn't work?
@instanttim It did, unfortunately, it didn't work with php 5.6, so I would need more testing into why the test failed. I currently am on a few other projects, the code is there if you want to take a look and see if anything stands out.
I had the same problem, there is an easy workaround. Just store the id as a field in the itemdata right after you create the item, then it will be available in the results() array.
$item = $database->get('yourNewId');
$item->set(['id' => 'yourNewId']);
$item->save();