ORM is a Pattern
blakefrost.tumblr.com
ORM is a Pattern
1–2 of 2 posts
Re: ORM is a Pattern
#2The best solution I've found is to drop all the fancy relational-like features of the ORM (lazy loading, etc) - use the databases native apis to query the data - it requires you to mostly understand what you're doing and your code is explicit in how it's accessing the database. But, objects are nice, so keep that part and use a simple object mapper to map the raw document to an object where it makes sense.
Building a simple object mapper on top of pymongo is actually really easy - I rolled my own in an afternoon - so I get objects where I want them without all the ORM-like crap. It's also really handy for enforcing some sort of schema in a schema-less database - most of the time I want a document to have a fixed set of fields, using the object mapper to enforce this handy and adding a field is easy provided you put a sensible default in the object for documents which won't have that field already.