Re: [sqlalchemy] Update multiple rows in SQLite Databse

2020-08-11 Thread Mike Bayer
since you need to track removals also I would likely keep track of individual data manipulation operations on the data from the point that it's loaded til the point that it's persisted again. The SQLAlchemy ORM's "unit of work" does exactly this, in fact, so if you loaded 25 Ingredient

[sqlalchemy] Re: Deletion of a row from an association table

2020-08-11 Thread William Phillips
For the sake of completeness I am including the code to disconnect an option from a machine using only python/SQLite code. def removeOption(bladeKey, OptionKey): """ DELETE from blade_options WHERE blade_FK == ? AND options_FK == ? """ import sqlite3 dbPath =

[sqlalchemy] Re: Deletion of a row from an association table

2020-08-11 Thread William Phillips
The situation is that I have two preloaded tables. The first is a Machine to which one or more Options can be added. The second table has Options can be connected to two or more machines. I've got the code to connect a machine with an option but I can't devise the code to reverse the

[sqlalchemy] Re: Deletion of a row from an association table

2020-08-11 Thread Jonathan Vanasco
Thanks. IIRC, I think you just need to set a custom cascade on these relationships (see https://docs.sqlalchemy.org/en/13/orm/cascades.html) I am not sure which option that would be, because it sounds like your application is behaving with a "delete-orphan", but that's not set. -- SQLAlchemy

[sqlalchemy] Re: Deletion of a row from an association table

2020-08-11 Thread William Phillips
full model for these 3 classes: # machine class Machine(Base): __tablename__ = 'machine' machine_ID = Column(Integer, primary_key=True) machine_Type = Column(Integer, nullable=False) machine_model = Column(String(10), nullable=False) machine_Weight = Column(Integer)

[sqlalchemy] Re: Deletion of a row from an association table

2020-08-11 Thread Jonathan Vanasco
Can you share the full model for these 3 classes, which includes the relationship declarations? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See

[sqlalchemy] Update multiple rows in SQLite Databse

2020-08-11 Thread William Phillips
I am developing a small cooking recipe application. I have a problem when it comes to updating data taken from a table (QTbableWidget). The updated data may contain more rows than the original already in the database ( or less). I usually use a dictionary with the keys corresponding to the

[sqlalchemy] Deletion of a row from an association table

2020-08-11 Thread William Phillips
I am working on an app using python3 and SqlAlchemy for SQLite3 database management. I have some tables that have a Many to Many relationship. I've created an association table to handle this relationship. Class Machine(Base): __tablename__ 'machine' machine_ID = Column(Integer,