Database allows new entries with the same primary key

I have noticed that Database collections allow entries with the same primary key - the key that is selected as a primary key by the user ant not the invisible primary key (ID the reference), is this a bug or it is by design?

I’m going to use hooks to ensure uniqueness of my selected primary key, can i send a custom error message to the DataSet that is trying to insert into the Database?

#Rawabi

Hi,
For your first question, its not a bug. it’s by design.
What are you trying to achieve ? What is the scenario ?
Roi

Hello,

I have connected a form with a Dataset, i can use pre_insert hook to achieve uniqueness of my selected primary key but is there any direct way in the api that allows me to specify what is the error exactly to the user without using a custom validation?

there is the onError event of a dataset but it does not seem that i can interact with it from the backend ? or there is anyway?

Have you tried onFailure Hook ?
Roi

Hello,

Thanks for your reply, but i want something that works on the front-end side. i have used the dataset feature to make the form, the form works fine and everything gets inserted - without me writing a single code, but since it allows multiple entries to have the same primary key,i want to reject those entries, i can reject them using the before_insert hook, but i want to notify the user on the front end that i rejected his entry?

Of course i can make this happen by not using a dataset and using my own custom code for inserting and updating but it would be easier just if i can notify the user about this single error.
Ehab