3

Is there a way to create an API rule that only allows the user to create a record if there isn't already one with the same combination of values. I want it to be possible to have a record with the values "a" and "b" and also one with the values "a" and "c" but not another one with the values "a" and "b".

I tried to do something like

NOT IN (SELECT ... FROM table WHERE value_1="a")
wafgawfwaf
  • 31
  • 1

1 Answers1

1

The most straightforward way seems to be to create a new index on those columns in the edit collection form and check the "Unique" toggle in the new index form.

TL;DR

Click on the collection you want to edit: Opening the New/Update Index form

Select "New Index" under unique constraints and indexes. In the New/Update Index Modal, you can toggle "Unique" and select from a list of presets (columns) to add them to the index. Selecting the name and avatar column for an index

See this comment from ganigeorgiev on github: https://github.com/pocketbase/pocketbase/issues/544#issuecomment-1477895278-permalink

Todd
  • 5,314
  • 3
  • 28
  • 45