Jon Nelson <jnel...@jamponi.net> wrote:
> I'm having a bit of trouble. > Let's say I have N primary key IDs for a set of objects. > I want to load all of those objects into the session, but I'd like that to > happen all in one query. > > dbsess.query(object_type).filter(object_type.primary_key.in_(some_list_of_ids)).all() > > # then I made (one or more) new instances using the same primary key as above > > new_instance = object_type(....) # NOTE: includes the primary key > > dbsess.merge( new_instance ) # this issues another query to load using the > primary key. > > > Instead of issuing N queries, I'd like to find a way to load the session with > all of the objects I'm (eventually) going to call merge on, and have that > happen in just one query if possible. > > I tried using merge_result but I'm pretty sure I'm not using it properly. > ok well the first query gives you those objects, in that session, in one query. i guess you’re trying to move them to a different session for the purposes of caching. so you could use either merge() or merge_result() but to avoid any SQL set load=False. You can look at the dogpile caching example for an example. > > > > -- > 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/d/optout. -- 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/d/optout.