Re: [sqlalchemy] Cascade child updates onto the parent

2020-05-28 Thread Colton Allen
Perfect. That's exactly what I ended up doing. I added events (after_insert/update/delete) for each backref. For each has-many relationship (through a secondary table) I had to consider the fact that the parent model would exist in session.dirty but not trigger the "onupdate" action on the co

Re: [sqlalchemy] Cascade child updates onto the parent

2020-05-28 Thread Mike Bayer
On Wed, May 27, 2020, at 3:57 PM, Colton Allen wrote: > Hello, > > I'm trying to automate a backref update. Basically, when a child model is > inserted or updated I want the parent model's "updated_at" column to mutate. > The value should be the approximate time the user-child-model was update

[sqlalchemy] Cascade child updates onto the parent

2020-05-27 Thread Colton Allen
Hello, I'm trying to automate a backref update. Basically, when a child model is inserted or updated I want the parent model's "updated_at" column to mutate. The value should be the approximate time the user-child-model was updated. The updated_at value would not have to match the created_a

Re: [sqlalchemy] Cascade relationship from child to parent

2018-09-15 Thread Mike Bayer
On Fri, Sep 14, 2018 at 4:46 PM, Edans Sandes wrote: > Hello, > > I got stuck on a problem related to relatioships and cascades. In the docs, > we have the following explanation: > > Cascades: > > > > Mappers support the concept of configurable cascade behavior on > relationship() constructs. This

[sqlalchemy] Cascade relationship from child to parent

2018-09-14 Thread Edans Sandes
Hello, I got stuck on a problem related to relatioships and cascades. In the docs , we have the following explanation: Cascades: *Mappers support the concept of configurable cascade behavior on relationship()

Re: [sqlalchemy] Cascade delete-orphan: reattach child to another parent

2018-03-31 Thread Serhii Mozghovyi
Many thanks! On Wednesday, March 28, 2018 at 6:42:16 PM UTC+3, Mike Bayer wrote: > > the backrefs intentionally don't keep fanning deep into object graph > for this kind of thing, so if you want it to go one hop further you > can add an event to do that directly: > > from sqlalchemy import even

Re: [sqlalchemy] Cascade delete-orphan: reattach child to another parent

2018-03-28 Thread Mike Bayer
the backrefs intentionally don't keep fanning deep into object graph for this kind of thing, so if you want it to go one hop further you can add an event to do that directly: from sqlalchemy import event from sqlalchemy.orm import attributes @event.listens_for(Address.user, "set") def _intercept

[sqlalchemy] Cascade delete-orphan: reattach child to another parent

2018-03-28 Thread Serhii Mozghovyi
Is it possible to make child objects (many-to-one side) delete itself from the old parent's collection when it is added to a different parent? See the file attached. The old parent remains unaware that he doesn't have this child anymore. P.S. session.expire() is an obvious solution but too heav

Re: [sqlalchemy] Cascade Delete, session confusion

2014-03-09 Thread Dmitry Berman
This makes a lot of sense, I just didn't realize how it worked... *When I did the following:* print inspect(Product1Mod1).deleted print inspect(Product1Mod2).deleted print inspect(Product1Mod3).deleted *Instead of just:* print Product1Mod1 print Product1Mod2 print Product1Mod3 This returned:

Re: [sqlalchemy] Cascade Delete, session confusion

2014-03-09 Thread Michael Bayer
On Mar 9, 2014, at 3:18 PM, Dmitry Berman wrote: > > print "\nQuery to check for changes with products and modules, shows that the > modules and product are gone:\n" > print Product.query.all() > print Module.query.all() > > print "\nThe modules below belong to the deleted product, they shoul

[sqlalchemy] Cascade Delete, session confusion

2014-03-09 Thread Dmitry Berman
Hi all, I just started using SQLA, and I am confused by some cascade delete behaviour I am seeing. Please see the code and tests below which show that the session is seeing table rows in one area and not in the other: CODE: print Product1Mod3 __tablename__ = 'products' id = Column(Inte

Re: [sqlalchemy] cascade delete in relationship and session.execute(table.update())

2012-01-06 Thread Wu-bin Zhen
I really appreciate your help! It works great without any problem. I tried session.refresh(storeobject) and I was wondering why it didn't work, now I learned the difference from your method. Again, thank you very much, and have a great weekend. On Tue, Jan 3, 2012 at 10:56 AM, Michael Bayer wrot

Re: [sqlalchemy] cascade delete in relationship and session.execute(table.update())

2012-01-03 Thread Michael Bayer
On Jan 2, 2012, at 4:06 PM, Wubin wrote: > > class Product(PolymorphicClass): #there are different types of the > product >__tablename__ = "products" >id = Column("id", Integer, primary_key=True, key="id") > name = Column("name", String(50), unique=True, nullable=False) >

[sqlalchemy] cascade delete in relationship and session.execute(table.update())

2012-01-02 Thread Wubin
Hi, Currently I am trying to implement a feature that transfers all products in a store to another store, and then destroy the old store which contains no product. The sqlalchemy version is 0.6.8. class Product(PolymorphicClass): #there are different types of the product __tablename__ = "

Re: [sqlalchemy] Cascade in many-to-many relationships: when orphans are not orphans

2011-08-25 Thread Michael Bayer
On Aug 25, 2011, at 7:06 PM, Benjamin Sims wrote: > Thanks for the help with my query the other day - as ever response was swift > and bang on. > > I'm now trying to set up another m:n relationship in ORM correctly. > Pseudocode: > > parentA.children.append(child1) > parentA.children.append(c

[sqlalchemy] Cascade in many-to-many relationships: when orphans are not orphans

2011-08-25 Thread Benjamin Sims
Thanks for the help with my query the other day - as ever response was swift and bang on. I'm now trying to set up another m:n relationship in ORM correctly. Pseudocode: parentA.children.append(child1) parentA.children.append(child2) parentB.children.append(child2) session.delete(parentA) At t

Re: [sqlalchemy] Cascade Deletes

2011-07-27 Thread Michael Bayer
On Jul 25, 2011, at 9:47 AM, Aviv Giladi wrote: > I can't seem to make cascade deletes work in sqlalchemy. > > I have a parent class (called Rating), a sub class (Subrating) and a > third class called SubRatingProperty. > > There is a one-to-one relationship between Rating and SubRating - each

[sqlalchemy] Cascade Deletes

2011-07-25 Thread Aviv Giladi
I can't seem to make cascade deletes work in sqlalchemy. I have a parent class (called Rating), a sub class (Subrating) and a third class called SubRatingProperty. There is a one-to-one relationship between Rating and SubRating - each Rating can only have one specific SubRating object. Next, the

[sqlalchemy] Cascade option, what does "all" mean?

2009-09-08 Thread Eloff
Hi, I see cascade='all, delete, delete-orphan' in the tutorial, but I thought I read in the docs elsewhere (can't seem to find the place atm) that all includes merge, delete, and others so that cascade='all, delete-orphan' should be equivalent? Is this correct? Thanks, -Dan --~--~-~--~-

[sqlalchemy] cascade="all, delete, delete-orphan" causes insert to fail

2009-01-28 Thread Gloria W
Hi again, I have a problem with a cascade relation. Any help or clues would be greatly appreciated. I have a model which has this relation: member = relation(Member,lazy=False,backref=backref ('members',order_by=memberID),cascade="all, delete, delete-orphan") When this cascade is active, it ca

[sqlalchemy] cascade delete-orphan

2009-01-15 Thread GustaV
Hi all, I try to set up a many-to-many relation with an association object. But I want something not usual: I want the child object deleted when not owned by any parent anymore. This is for a messages/recipients relation: the message is useless when everybody removed it from its mailbox! I tried

[sqlalchemy] cascade

2008-12-23 Thread justmike2...@gmail.com
I seem to be running into a problem with implementing cascades in sqlalch. Next to my ForeignKey() I have ondelete and onupdate both set to "CASCADE" and in my mapper I have this: mapper(queue, queue_table, properties=dict(parent=relation(queue, backref='JOBS'))) However the cascade is not bein

[sqlalchemy] cascade defaults

2008-09-24 Thread az
hi i have cascade= option of relation switched automaticaly between "all" and other values, and nothing. so i used cascade=None as nothing, hoping it will get the default behaviour. the result was some query got 6x slower (actualy thats why i went hunting it)... nope, it happens that source-wi

[sqlalchemy] cascade="all, delete-orphan" => FlushError, instance is an unsaved, pending instance and is an orphan

2007-06-28 Thread znerol
Hi All Yes, i know, there is a FAQ-entry and i realized that this issue was discussed before. Regretably i'm not able to make things work with a one-to-many relationship using cascade="all, delete-orphan". Now i discovered that even the example from the documentation raises this exception (1). I'

[sqlalchemy] cascade='all, delete-orphan' causing error about unsaved, pending instances

2007-05-16 Thread Andreas Jung
I am building a media database using SA where the model basically maps Medium --1:N--> Versions --1:N--> Files My code for creating new Medium instances based on an import script basically is doing the following: f = File(...) v = Version() v.files.append(f) m = Medium() m.versions.append(

[sqlalchemy] Cascade-Delete causes AssertionError (Tries to blank-out primary key ...)

2007-02-11 Thread Nebur
The example below raises an: sqlalchemy.exceptions.AssertionError: Dependency rule tried to blank- out primary key column 'userdata.user_id' on instance '[EMAIL PROTECTED]' The code creates 2 objects having a 1:1 relation with cascade-delete. The ForeignKey is declared as a primary key. This seem

[sqlalchemy] Cascade delete-orphan: child deleted althought still referenced ?

2006-12-19 Thread Nebur
I create a child table and a parent table. The latter holds a relation to the child with delete-orphan cascade. When I delete _the first_ of my 2 parents, the child is immediately deleted, too. *** This is my first attempt to use delete-orphan. I don't dare to report it as a bug, for the case I mi

[sqlalchemy] Cascade performance

2006-11-28 Thread Daniel Miller
Lately I've been noticing severe slowness when instantiating new SA objects. I can't say for sure, but it seemed to get worse with the 0.3 release. A test program is attached. Here's some sample output: Create forward associations Time to create item 0: 0.06071 sec Time to create item 1: 0.05977