Example:
in the database I have a record such as this:
{
id: 53,
part_number: 'MOTOR-OIL',
description: 'Motor Oil'
}
I wish to use a link that displays this record. I could refer to the record like so, using the surrogate key:
http://localhost/show_record/53
or I could use an domain-specific identifier like so, provided it's unique:
http://localhost/show_record/MOTOR-OIL
Is there a best practice of a framework relating to deciding which one to use? Is it acceptable to use the surrogate key?
Notes:
In my case, the surrogate/artificial key is a PRIMARY KEY
and quite unlikely to change. The part number however might change, while retaining the same surrogate key.
In my case the domain entity's part_number
is unique, but in the general case, it may not be the case, and more parameters may be required to uniquely identify a record, while id
being a surrogate key will typically remain unique per various database conventions.