summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-02-11 10:52:00 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-02-11 10:52:00 -0500
commit8c1bf8cdd0f510173534aeccda45a44bb7ed4626 (patch)
tree1fbfd1a56250efe743cbd8afd0c85d06f8cf85d7
parentb0be3ef1b220edc64b3a72f3cf390f86eef8a7f9 (diff)
downloadsqlalchemy-8c1bf8cdd0f510173534aeccda45a44bb7ed4626.tar.gz
document identity_map
-rw-r--r--doc/build/orm/session.rst7
-rw-r--r--lib/sqlalchemy/orm/session.py13
2 files changed, 20 insertions, 0 deletions
diff --git a/doc/build/orm/session.rst b/doc/build/orm/session.rst
index 298f2ea29..4bb1738ba 100644
--- a/doc/build/orm/session.rst
+++ b/doc/build/orm/session.rst
@@ -890,6 +890,13 @@ all objects which have had changes since they were last loaded or saved (i.e.
# persistent objects that have been marked as deleted via session.delete(obj)
session.deleted
+ # dictionary of all persistent objects, keyed on their
+ # identity key
+ session.identity_map
+
+(Documentation: :attr:`.Session.new`, :attr:`.Session.dirty`,
+:attr:`.Session.deleted`, :attr:`.Session.identity_map`).
+
Note that objects within the session are by default *weakly referenced*. This
means that when they are dereferenced in the outside application, they fall
out of scope from within the :class:`~sqlalchemy.orm.session.Session` as well
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 4299290d0..ba6ceaeec 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1772,6 +1772,19 @@ class Session(object):
return self.transaction and self.transaction.is_active
+ identity_map = None
+ """A mapping of object identities to objects themselves.
+
+ Iterating through ``Session.identity_map.values()`` provides
+ access to the full set of persistent objects (i.e., those
+ that have row identity) currently in the session.
+
+ See also:
+
+ :func:`.identity_key` - operations involving identity keys.
+
+ """
+
@property
def _dirty_states(self):
"""The set of all persistent states considered dirty.