On Friday, February 28, 2014 2:33:11 PM UTC-5, Michael Bayer wrote: > > OK well it has to emit the SELECT for the primary row, but yes > populate_existing will overwrite, so really, just any equivalent of > query(User).filter_by(primary key).first() is really all you need here…we > used to have a load() method that did this but it fell out of repair and > nobody missed when i removed it, wasn’t worth maintaining. The internal > stuff used by get() in the “loading” module can probably be worked to > provide this feature similarly to how get() works. >
I hit the DB too many times when I used `query(User).filter_by(primary key).first()`; I recently switched from a janky internal storage mechanism to using SqlAlchemy's session storage via `get()` to avoid this problem. it was working fine. So, now I'm just doing something like this: def get_Object_by_id(dbSession, id, eagerload_a ): q = dbSession.query( Object ) eagerloads = [] if eagerload_a eagerloads.append( joinedload('a') ) if not eagerloads : return q.get(id) q = q.options(eagerloads) return q.filter(Object.id==id).first() -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.