revert() after a save() does not work with Schema defined properties
Investigating the problem lead me down the commit -> utils.plainCopy -> utils.copy -> utils.forOwn -> Object.keys() chain. Object.keys() requires enumerable to be set true on the descriptors. Indeed the current code defaults to this:
var makeDescriptor = function makeDescriptor(prop, schema, opts) { var descriptor = { // Better to allow configurability, but at the user's own risk configurable: true, // These properties are enumerable by default, but regardless of their // enumerability, they won't be "own" properties of individual records enumerable: schema.enumerable === undefined ? true : !!schema.enumerable };
The problem though, is that descriptors on the prototype aren't inherited by the instance .e.g. Object.getOwnPropertyDescriptor will return undefined0.
As a result instance._get('previous') (created with plainCopy()) fails to preserve the schema defined properties after save(). Which amongst other things breaks revert()
My understanding is that we either have to use for (var attr in obj) or keep our own list of defined properties (e.g. join Object.keys with the attrs sourced from the Schema). Because getOwnPropertyDescriptor returns undefined we cannot simply add in enumerability on the init.
The solution for this might be a good place to deal with #269 ?
0 (For some reason I cannot find the specification for descriptor inheritance in the MDN define property docs ) so I'll use this for reference instead http://ejohn.org/blog/ecmascript-5-objects-and-properties/.