you can check if an object is an "orphan" related to a certain relation()
its supposed to belong to, though there's no automated way to go from that
object to the actual collection it was removed from unless you scan
through all the potential parents in the session and check each one.

the current way to check for an orphan is and internal thing at the
moment, and looks like:

some_relation.mapper._is_orphan(attributes.instance_state(item))


Joril wrote:
>
> Hi all,
> in my application I have a "logical deletion" system so that every
> table has a "logically_deleted" flag to be used instead of physical
> deletion. It works fairly well but I'm still missing something: when I
> remove an element from a relation I'd like to be able to mark that
> element as "logically_deleted" too, is there a way to ask SQLAlchemy
> about that element?
> For example, in a simple one-to-many all-cascaded relation between
> classes A and B:
>
> b1 = B()
> b2 = B()
> a1 = A()
> a1.children = [b1, b2]
> session.add(a1)
> session.flush()
>
> Now, if later I remove b2 from the "children" collection, can I ask
> SQLA about it? That is, about a1's orphans?
> (Please note that the application never removes b2 explicitly, it just
> changes a1.children)
>
> Many thanks!
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to