diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-02-20 18:24:46 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-02-20 18:24:46 -0500 |
commit | 26fb4b81638189547dd24f525ad0d146f2646916 (patch) | |
tree | ad77d18c6ea7246cfc34666459123e4432564361 /lib/sqlalchemy/orm/util.py | |
parent | 6d1c473c4726533764e0d46446abb41c79109f10 (diff) | |
download | sqlalchemy-26fb4b81638189547dd24f525ad0d146f2646916.tar.gz |
- Added new helper function :func:`.was_deleted`, returns True
if the given object was the subject of a :meth:`.Session.delete`
operation.
- An object that's deleted from a session will be de-associated with
that session fully after the transaction is committed, that is
the :func:`.object_session` function will return None.
[ticket:2658]
Diffstat (limited to 'lib/sqlalchemy/orm/util.py')
-rw-r--r-- | lib/sqlalchemy/orm/util.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 492523e63..cc9dd6ba5 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -1210,9 +1210,30 @@ def _orm_columns(entity): def has_identity(object): + """Return True if the given object has a database + identity. + + This typically corresponds to the object being + in either the persistent or detached state. + + .. seealso:: + + :func:`.was_deleted` + + """ state = attributes.instance_state(object) return state.has_identity +def was_deleted(object): + """Return True if the given object was deleted + within a session flush. + + .. versionadded:: 0.8.0 + + """ + + state = attributes.instance_state(object) + return state.deleted def instance_str(instance): """Return a string describing an instance.""" |