I
I
ImPuuLsE2016-06-12 22:36:59
Yii
ImPuuLsE, 2016-06-12 22:36:59

What is the reason for the simultaneous creation of the same objects in MySql and Yii2?

Hello! I cannot understand how identical records can be added to the database, provided that there is a model (in Yii2) in which 2 fields (email, username) are unique.
Those. if you send 1 request, then the second request with the same data is not recorded, validation works. I made a simple authorization through React Native, and Yii2 rest api.
If you press the registration button several times quickly, then ne number of identical records fly into the database (checked through the android emulator). The request is made via fetch . Does anyone have any thoughts on this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
devian3000, 2016-06-14
@devian3000

the decision in a forehead - make unique indexes on columns at the DB level.
If this is implemented only at the code level, then it can happen like this.
Two requests are sent.
The first request is validated, it is checked that the email is unique and sent for recording.
At this moment, the second request is checked, if the first one did not have time to register in the database, then it turns out that the email is unique again, and the second entry goes to the database, etc.
It is necessary to overlap at the DB level.
Yes, and on the front, through REST, block the send until the response returns.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question