question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion : make record.getOne() able to filter over other fields than id

See original GitHub issue

Hi,

The current prototype of the record.getOne methods only allows filtering over the ID only since it is a mandatory parameter of the function, however one might want to use this function with another unique & required field of the collection, for example a slug, but doing so is currently impossible with record.getOne.

One workaround I found was to use record.getFullList() with a filter on the desired field, but it seems kind of counter-intuitive and imperfect to use the method that queries the whole collection and is expected to return multiple results when you actually want a single record. This workaround also causes a problem when someone wants to set different permissions on the list and view actions on the API for their collection but is forced to use record.getMultiple to compensate for the limitation of the current implementation of record.getOne.

I would therefore suggest changing the signature + implementation of the record.getOne function or adding a new one to give users an option to allow for searching over other unique+required fields than the id of the record.

Thanks in advance for your consideration ! 😃

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ganigeorgievcommented, Nov 6, 2022

@goknsh Because that’s how devs most likely are going to use it, otherwise the returned record from the collection will be arbitrary and you’ll rely on whatever is the first row in the db query select * from yourCollection limit 1;.

In the rare cases where you don’t need a filter and don’t care what record is returned, you can use just getList(1, 1)

1reaction
ganigeorgievcommented, Nov 6, 2022

In the upcoming v0.8.0 there is a new helper getFirstListItem(filter, queryParams = {}) that could be used for fetching the first found record matching a filter. As the name suggest, the above for now works only with the “List API rule”.

Please note that v0.8.0 will have some breaking changes and will work only with PocketBase v0.8+. You can check the rc branch with the updated RecordService methods in https://github.com/pocketbase/js-sdk/tree/rc#recordservice.

SDK changelog with the future changes could be found in https://github.com/pocketbase/js-sdk/blob/rc/CHANGELOG.md.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apply a filter to view select records in an Access database
Filtering is a useful way to see only the data that you want displayed in Access databases. You can use filters to display...
Read more >
How to filter array when object key value is in array
Then he uses the filter function on the data.records array and says "remove all items that do not have an ID matching one...
Read more >
Reports: Is is possible to filter by type of Document ID ...
Solved: Hello, I need to filter a report based on two variables which are of type Document ID. The out-of-the-box filters seem to...
Read more >
Filter Reports Using Field Comparisons with Field-To-Field ...
Field -to-field filters let you filter a report by comparing the values of two different report fields. For example, see cases modified after...
Read more >
Changing filter suggestions | Looker
suggestions lets you hard-code a list of possible filter suggestion values. This can be useful if you do not want certain data values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found