Thank you Mike!

So suppose I have an a Manager object *manager* and I wanted to promote 
that to Engineer:

# Modify the persisted data of the manager object in the db directly.
session = object_session(manager)
session.execute(manager.__table__.update() \
                                 .where(manager.__table__.c.id == manager.id
) \
                                 .values({'type': 'engineer'}))
# session.flush() ?

# Expunge the object.
session.expunge(manager)

# Subsequent reads would then return Engineer objects…

I suspect that modifying the object directly would not work with expunge(). 
However, if I wouldn't expunge() and all I do is modify the object then 
perhaps that's ok?

# Modify the object's type directly, then manager's class would not be 
accurate anymore.
manager.type = "engineer"

Also, if for some reason the session were to rollback() then the above 
execute() would not be persisted and manager remain a manager. Correct?

Thanks!
Jens


On Thursday, August 10, 2017 at 5:25:37 PM UTC+2, Mike Bayer wrote:
>
> > Talking about the example in the documentation, do I understand you 
> > correctly that changing from Manager to Engineer is as simple as 
> updating 
> > the type field? 
>
> yes.   also locally you want to clear out those objects from your 
> Session and reload (cleanest would be to expunge() totally). 
>
>

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

Reply via email to