Added support for Array property type; force update of composite properties; added support for non-ObjectID IDs. #387
+49
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 likeobj.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. :)