strongloop/loopback-datasource-juggler — pull request #290 by fabien (2014-09-05 14:42:48+00:00)
Title: Enforce id (prevent user-set value), fix isNewRecord

This implements https://github.com/strongloop/loopback-datasource-juggler/issues/253

However, for now this kind of validation is an optional setting: `{ forceId: true }` (on model definition). I think it makes sense to enforce by default (essentially, use `settings.forceId !== false` instead). Users should not be able to mess with primary keys, unless there's a good reason for it. Especially if the property type is `Number` - I can see that string values (a.k.a. slugs) might make sense. The `forceId` key is currently used for the same kind of feature, in embedsMany relations.

To correctly implement this behavior (and to re-use the validations functionality), I had to resolve an old issue (see https://github.com/strongloop/loopback/issues/388). The `isNewRecord` check was unable to tell the difference between a new record or one that had its id set explicitly (but still was new).