dresende/node-orm2 — pull request #387 by rafaelkaufmann (2013-11-17 00:10:56+00:00)
Title: Added support for Array property type; force update of composite properties; added support for non-ObjectID IDs.

I know it's bad form to put two different features on the same pull request, but they're both rather short, so.

Up until now, Array wasn't a valid property type -- something that was sorely missing for MongoDB-backed models. In order to make this possible, I had to make some substantial changes to the MongoDB driver, in particular the assumptions it makes about the changes parameter in update operations. Caution is required!

Property.js seemed to be the only module that cared about the type of properties, but maybe something else needs to be changed. That said, everything works normally.

As I added the Array type, I realized my updates to Array-typed properties weren't getting persisted. This goes down to the treatment of property changes on the custom setter. Thus `obj.arrayProp = ['foo']` would work, but something like `obj.arrayProp[0] = 'foo'` would go unnoticed by ORM. (Obviously, this is also an issue for Object-typed properties.)

Rather than attempting to overload all possible methods that could cause changes to these properties, I forced savePersisted to update all Array- or Object-typed properties.

This sidesteps a bit of a pressing issue: as I've mentioned previously, ideally there should be support for MongoDB's atomic `$push/$pull`/etc operators on array properties (currently, the driver assumes `$set`). Clearly this is hard, but it might be worth it (and the lowly CakePHP driver does it, so...).

Finally, I've added support for having ids on MongoDB-backed instances that are NOT instances of `mongodb.ObjectID`. This is obviously undesirable but (unfortunately) occurs on one of my existing applications, so there it is. :)