On Aug 21, 2013, at 3:40 PM, Ryan Hiebert <
ry...@ryanhiebert.com> wrote:
> If I use truly surrogate keys in my database, I really don't want to
> expose any database primary keys, instead creating some other column
> for that identification, set with a unique constraint. Otherwise, that
> new ID will end up becoming "business logic", and I'll have destroyed
> the value of my surrogate keys.
There is no obligatory, or even assumed, requirement that the {id} in the resource (URL) is identically the primary key in the database. Pick whatever mapping seems right between resource and data (controller, model, and storage).
I'm not clear why your DB primary keys could "become business logic." I've worked in contexts where certain operations (like updates) could change the DB auto-generated "row number", is it something like that?
It is, however, expected that "/resource/{id}" is a reliable, persistent identifier of the same object forever, which was not the case for the auto-generated DB row ID in the context I mentioned, so we had to create another column for that. We also had to mark the created column as the primary key, both for the DB and the model, since internal logic was just as dependent on a persistent object id. Is your "surrogate" something of this sort?