I have added a new sub class to my model hierarchy. I would like to 
instantiate it however there will be cases where the base object / row 
already exists. I tried to solve this by passing in the user object to the 
StaffUser but it looks like sqla still tried to INSERT into the User table 
leading to an unique constraint violation. My models are:

class User(db.Model):
    id = db.Column(UUID, default=uuid.uuid4, primary_key=True)

class StaffUser(User):
    id = db.Column(UUID, db.ForeignKey(User.id), primary_key=True)

    user = db.relationship(User

is there anyway to tell sqla to re-use an existing base instance (ie to not 
attempt an insert)?

user = User.query.get(id)
staff_user = StaffUser(user=user)


-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to