On 5/26/15 11:37 AM, c.bu...@posteo.jp wrote:
Can someone explain me the difference between expunge() and
make_transient() please.

Of course I read the docs (more than one time) about it. But I am not
really sure about the difference.

expunge sends a "persistent" object to the "detached" state. make_transient converts a "persistent" object to a "transient". These states are described at http://docs.sqlalchemy.org/en/rel_1_0/orm/session_state_management.html#quickie-intro-to-object-states.

The difference in concrete terms is whether or not the object is associated with a primary key identity, such that when it is re-associated with a Session, we know whether this object should be subject to an INSERT or to an UPDATE.

You can view this identity as follows:

from sqlalchemy import inspect

inspect(my_object).identity_key


as well as the state:

inspect(my_object).transient
inspect(my_object).persistent


see the docs for InstanceState at http://docs.sqlalchemy.org/en/rel_1_0/orm/internals.html#sqlalchemy.orm.state.InstanceState


--
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to