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
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
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 =
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
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
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)
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
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 =
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
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
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
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
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
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
14 matches
Mail list logo