Simon, Thanks for taking the time to read through and respond.
> 2) Do I need to be doing the manual "flush() + get ID" fiddling to create > > the linkage between objects? Or is there a better way to do this, eg by > > linking the objects together in code and making a single session call at > the > > end to insert all the rows in one hit? > > Linking the objects would be easy to do, and might make the code > clearer. You would get rid of your calls to session.flush, and rather > than assigning to hardware_id, tag_id and so on, you would have: > > hw_dict['tag'] = tag_obj # for the hardware-tag relationship > > hw_obj.mods.append(Mod(**m_dict)) # for the hardware-mod relationship > etc. > Ah, it's that simple! I knew I was missing something. Thanks. > > > 3) What's 'best practice' for transaction management with SQLAlchemy > ORM? > > The documentation provides a snippet for a context manager called > > session_scope(); is there anything like that built-in that I > could/should be > > using? > > http://docs.sqlalchemy.org/en/latest/orm/session.html > > It really depends on the application. For example, web applications > tend to be different to traditional GUI applications, which are > different again from quick scripts. > I see. In this case it is a Flask application, but I'm trying to keep the database layer in its own module. I'm definitely finding that with SQLAlchemy there are many ways to skin a cat, which is great, but is making it a bit tough for me while I'm getting started. Thanks again. -- 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.