From 86900687f13c097d287d527e0437dd6f94339627 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 10 Sep 2015 10:00:46 -0400 Subject: [PATCH] - add a new FAQ recipe for "walk all objects", replacing the need to use mapper.cascade_iterator() for this purpose as it was not really designed for that use case. Add docs to cascade_iterator() pointing to the recipe. fixes #3498 (cherry picked from commit 03797b78475bec9fb9c15f8e926414f3720a273c) --- doc/build/faq/sessions.rst | 71 ++++++++++++++++++++++++++++++++++++ lib/sqlalchemy/orm/mapper.py | 17 +++++++-- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/doc/build/faq/sessions.rst b/doc/build/faq/sessions.rst index e3aae00ce2..a89b3765c7 100644 --- a/doc/build/faq/sessions.rst +++ b/doc/build/faq/sessions.rst @@ -417,6 +417,77 @@ The recipe `ExpireRelationshipOnFKChange + <__main__.B object at 0x103025210> + <__main__.B object at 0x10303b0d0> + <__main__.C object at 0x103025490> + + + Is there a way to automagically have only unique keywords (or other kinds of objects) without doing a query for the keyword and getting a reference to the row containing that keyword? --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 59d0eb9e9e..6ba5288ed7 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -2467,15 +2467,24 @@ class Mapper(_InspectionAttr): for all relationships that meet the given cascade rule. :param type_: - The name of the cascade rule (i.e. save-update, delete, - etc.) + The name of the cascade rule (i.e. ``"save-update"``, ``"delete"``, + etc.). + + .. note:: the ``"all"`` cascade is not accepted here. For a generic + object traversal function, see :ref:`faq_walk_objects`. :param state: The lead InstanceState. child items will be processed per the relationships defined for this object's mapper. - the return value are object instances; this provides a strong - reference so that they don't fall out of scope immediately. + :return: the method yields individual object instances. + + .. seealso:: + + :ref:`unitofwork_cascades` + + :ref:`faq_walk_objects` - illustrates a generic function to + traverse all objects without relying on cascades. """ visited_states = set() -- 2.47.3