I’m just trying to increment a record by 1 starting at 2000, when a new record is created upon clicking on the create action to create a record:
if resource_model == Student then @resource.testing_id = id + 2000 end
So if the record has an id of 1, I assume that the testing_id will be 2001. But instead it returns:
2147483647 (maximum mysql limit?)
Any suggestions on how to address this? Thanks.
You can’t know record ID during create. ID is known after saving record do database.
You can’t relay on ID to give you values like 1, 2, 3 … and so on.
Don’t store value like ID+2000, becouse you can get it at any time by calculating id+2000.
You can get next
testing_idby something like this:But if two processes at the same time will fetch the same value then you will have duplicate
testing_id.