As the title suggests, I want to add a row with an id based on another row in SQLALchemy. Currently, I'm adding an extra select
, but I'd like to get rid of this. I know this is possible in MySQL, so I'm just trying to figure out the SQLAlchemy version. Here's what I currently have:
keywords = ['a', 'b', 'c']
prefix_id = session.query(Prefix.id)\
.filter_by(name=some_prefix).first()[0]
inventory_item = InventoryItem(
item=some_item, prefix_id=prefix_id, address=some_address)
inventory_item_metas = [InventoryItemMeta(
inventory_item=inventory_item,
type='keyword',
value=keyword) for keyword in keywords]
Note that I'm adding more items based off the id returned, so I'd like to do everything in one transaction as efficiently as possible.