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.
Going to use the example from the documentation, as hopefully that will
give me the hints needed to handle my more complicate case.
Using SQLAlchemy 1.4 ORM and Joined Table Inheritance
# Define Base Class for Inheritance
class Employee(Base):
__tablename__ = 'employee'
id = Column(Integer, primary_key=True)
name = Column(String(50))
type = Column(String(50))
__mapper_args__ = {
'polymorphic_identity':'employee',
'polymorphic_on':type
}
# Define some Sub-classes
class Engineer(Employee):
__tablename__ = 'engineer'
id = Column(Integer, ForeignKey('
employee.id'), primary_key=True)
engineer_name = Column(String(30))
__mapper_args__ = {
'polymorphic_identity':'engineer',
}
class Manager(Employee):
__tablename__ = 'manager'
id = Column(Integer, ForeignKey('
employee.id'), primary_key=True)
manager_name = Column(String(30))
__mapper_args__ = {
'polymorphic_identity':'manager',
}
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?
--
Richard Damon