Upgrading an ORM object from a base class to a derived class.

6 views
Skip to first unread message

Richard Damon

unread,
Apr 16, 2021, 9:26:33 PM4/16/21
to sqlal...@googlegroups.com
Using SQLAlchemy 1.4 latest, intending to keep upgrading and moving to 2.x

Using ORM with Joined Table Inheritance.

Have an object in the database as an instance of the base class, which
has a lot of data in it, and want to upgrade it to be an instance of
derived class. So in the examples, promote an plain Employee to be an
Engineer or a Manager.

If not using ORM and willing to just duplicate code, I would just write
the new data to the associated derived table and then change the type
field in the base table, but this seem 'crude'. Is there a better way to
let me use the ORM structures to actually do some of the work?

I don't think I can just create a new derived object with the original
primary key, as that will get rejected as a duplicate key, not replace
the object.

--
Richard Damon

Reply all
Reply to author
Forward
0 new messages