Get one item with constraint

Dear Bubblers,

manytimes I need only one item from the database constraint by unique id or slug. Then I need to use Search for XXX:first item.

I mean, it will be great to have functionality like Get one item and it will be constraint only by unique id or slug. You can see on the sketch:

Have a nice day
Petr Majtán,

Better to have a list of one than “get one” returning a list.

Hi @NigelG thank you for your answer. Please, can you explain me why is better to have a list of one than “get one”?

What would you want to happen if “Get One” actually returned more than one row?

Great question. I thought about it and this is why I wrote: Get one item and it will be constraint only by unique id or slug.
Because when this function will have the required constraint (only by unique id or slug), it’s not possible to return more than one row.

What if your slug is not unique? What if there is a database error and you have duplicate unique ids?

You simply cannot, even with database constraints built-in (which we don’t have) guarantee uniqueness.

Saying “That will never happen” means it will happen in the first 5 minutes :smiley:

That is why DB2 (ur-relational database) has an error code -811.

“Execution of an embedded SELECT statement or a subselect in the SET clause of an UPDATE statement has resulted in a result table that contains more than one row. Alternatively, a subquery contained in a basic predicate has produced more than one value.”

So, if IBM haven’t been able to do this in 35 years, you can’t!

The only way would be have some sort of error that you can then handle. But that would be horrible.

It’s legitimate concern. You have two perspectives. For me is better second one - To see error and resolve it, than to hide error by :first item and update another database item than I wanted :slight_smile:

1 Like

Bubble doesn’t handle workflow “errors” very well as it is. Well, it doesn’t handle them at all !