-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for Array property type; force update of composite properties; added support for non-ObjectID IDs. #387
base: master
Are you sure you want to change the base?
Conversation
@spartan563 , is this what you had in mind? (Grumpy mode on: this would have been tremendously easier if these functions could directly access |
BTW, I did test it with my app and it did have the desired behavior. However, you're right that it's still missing the corresponding fixes for the |
I can't even get As for your recommended change, there's a slight problem: when passing the DB config in URL format (which is what the I'd patch the relevant code in
|
Yeah, there are a few tricks that I usually apply to get it running for myself. I've always had issues with the sqlite3 driver on my machine (Windows) so I make the following changes: test/common.jsI change common.protocol = function () {
return process.env.ORM_PROTOCOL || 'mongodb';
}; test/integration/orm_exports.jsI comment out the ///var sqlite = require('sqlite3'); Ah, I see what you mean. I don't see any problems with implementing the parsing logic you've shown - seems like it's the most straightforward way to handle it. |
…mple properties had changed
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. :)