Does anyone have any suggested best practices for ensuring unique values in Primary Fields for user-generated records (i.e. records created from a page with input elements on it)?
Right now, my current solution is to:
1) Use a text field labelled something like “Record Number” as the primary field of my main collection
2) Create a separate, one-row collection storing the next record number (also as text)
3) Whenever a user submits an insert to my main collection I use a hook to get the next record number from the next record number collection, set the primary field of the main collection to it, and then increment the value in the next record number collection
I know uniqueness in the Primary Field is recommended to avoid bad things with dynamic pages and reference field integrity, but this seems really clunky, so maybe I’m missing something. And although I haven’t experimented this far yet, I’m guessing I may also have to code hooks to insert reference field values into records in related collections. I was expecting something more like Access’s autonumber option for fields.
I do understand the difference between Primary Fields and the _id system field, and the fact that one can’t use _id as the primary field.
Anyone got any guidance on this?