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

2020-08-19 Thread William Phillips
Sorry I was not back sooner. Thank-you Simon King, you have solved my problem. As anyone can guess I am still in the learning stages of SqlAlchemy. My python/Sqlite solution has shown that I have neglected SqlAlchemy core. When I first downloaded and studied SqlAlchemy, I only glanced at

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

2020-08-15 Thread Simon King
SQLAlchemy normally presents a many-to-many relationship as a list on both sides. You've got "Machine.children", which is a list of Options, and "Option.parents", which is a list of Machines. If you remove one of the options from a machine.children list, you'll find that SQLAlchemy removes the

[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] Re: Deletion

2011-10-19 Thread Fabien Ribes
You're right ! Thanks On Oct 18, 7:32 pm, Mike Conley mconl...@gmail.com wrote: How are you doing the delete? This should delete both.     a = sess.query(Peripheral).filter(Peripheral.label=='some label').one()     sess.delete(a)     sess.commit() This will not work.     a =

[sqlalchemy] Re: Deletion

2011-10-19 Thread Fabien Ribes
On Oct 18, 8:01 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Oct 18, 2011, at 10:03 AM, fribes wrote: Hi all, Despite some doc and web digging, I didn't find how to tell sqa to behave the way I want : on deletion on Peripheral, also delete in Actuator. with the following

Re: [sqlalchemy] Re: Deletion

2011-10-19 Thread Michael Bayer
On Oct 19, 2011, at 3:55 AM, Fabien Ribes wrote: usually relationship() with cascade=all, delete-orphan is used for this use case, so that SQLAlchemy can maintain knowledge about the link between Peripheral and Actuator. The other alternative is to use ON DELETE CASCADE on the foreign

[sqlalchemy] Re: Deletion order during flush is not correct.

2010-12-15 Thread Will
An update. This problem does occur with sqlite it's just that sqlite doesn't enforce the foreign key so it doesn't throw an exception. # output that deletes in the proper order 2010-12-15 14:33:52,197 INFO sqlalchemy.engine.base.Engine.0x...d050 BEGIN (implicit) 2010-12-15 14:33:52,197 INFO

[sqlalchemy] Re: Deletion of referenced objects fails

2007-10-30 Thread Michael Bayer
On Oct 30, 2007, at 5:41 AM, Felix Schwarz wrote: foo = session.query(User).filter_by(name='Foo Bar').one() session.save(foo) for address in foo.addresses: foo.addresses.remove(address) session.delete(address) session.delete(foo) foo = User() session.save(foo) foo.id = 1

[sqlalchemy] Re: Deletion of referenced objects fails

2007-10-30 Thread Michael Bayer
On Oct 30, 2007, at 5:41 AM, Felix Schwarz wrote: for address in foo.addresses: foo.addresses.remove(address) session.delete(address) session.delete(foo) foo = User() session.save(foo) foo.id = 1 foo_addr = Address() session.save(foo_addr) foo_addr.street = Picadelly

[sqlalchemy] Re: deletion behavior question

2007-02-12 Thread Michael Bayer
On Feb 12, 3:00 pm, iain duncan [EMAIL PROTECTED] wrote: I would like some objects that are related through many to many tables to delete the many to many entry on deletion, but NOT the endpoint. It seems that cascade=all deletes both, and no arg to cascade leaves left over invalid entries