Saturday, September 22, 2012

Getting upserts working for single-collection inheritance in MongoMapper

I've found that when one does an upsert using one of the modifiers (increment, set, push, etc.) on a derived document class (i.e. using single collection inheritance), if the document doesn't exist, then the newly created document doesn't have _type set. 

I've gotten around this by overriding criteria_hash() in MongoMapper::Plugins::Sci::ClassMethods as follows:


Let me know if you see any problems this could introduce or whether there are ways in which it's not a comprehensive solution.

Hopefully this will make its way into the master branch.

Cheers,
Kevin

No comments: