On 5/2/21 6:34 PM, Mike Bayer wrote: > > > On Sun, May 2, 2021, at 4:44 PM, Richard Damon wrote: >> I asked this a bit ago, but never got an answer, so trying again wording >> a bit different to see if I can get help. > > sorry if this got missed. > >> >> The question is, given an existing record for an 'Employee', how to I >> change it from an Employee to say an Engineer. I don't want to make a >> 'new' record with a new ID number, as the id number is referenced in >> other tables. >> >> >> Not using ORM, it would be a simple matter of writing the data into the >> Engineer table with an INSERT, forcing the ID to match the ID of the >> employee, and then change the value of the type field in the Employee >> table with an UPDATE. The question is, is there a more "ORM' way to >> do this? > > this request comes up from time to time however the Core method you > refer towards is the best way to do this. This kind of operation is > unusual enough that it's simpler for users to write the Core routine > they want for their needs rather than adding a complex generalized > feature to the ORM that would not be used often and would be difficult > to develop and support.
Ok, understand. Maybe my application is a bit unusual, but it seems I will be doing this a LOT. In my case nothing will REALLY be the base class, but many of the sub-classes will have relations referencing the id number of in the base class, and when importing a change set from an external source, those id numbers might not match, so the base class includes a UUID to match things up, and to avoid foreign key errors in some of the derived objects, it seems I want to first make a pass to create all the new nodes as just the base class so they don't create broken relationships, and then upgrade them to their final type so I can fill in the relationships. Since many of the relationships will by cycles, I can't start at the base and build up. I presume that after changing the base record I should tell SQLAlchemy to flush the old record out of its cache so it will re-read it with its new identity. -- Richard Damon -- 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 http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/d7b66178-52bd-60cc-b8bd-655d46e535af%40Damon-Family.org.