The upshot is that it's not possible to get this data in after_flush
> without the load occurring ahead of time.  So add a before_flush() method
> that iterates through everything and loads all collections you care about,
> then they should be present by the time you get to after_flush().

Ok, I have to look into the before_flush event to make sure I have enough
info to target only updated instances. e.g. If there are 1,000 books in the
session, and one chapter gets moved between 2 of them, I don’t want to load
the chapters relationship of all books in before_flush.

Alternately, I might be able to do what I need to do if I can get the value
of chapter.book or chapter.book_id prior to the flush. load_history() tells
me the value that’s about to be flushed: how do I get the original value?

In case you’re interested, what I’m trying to do is write a tool which
syncs a RDBMS with a document store. The user defines Collections, which
specify columns and nested relationships which should be persisted. For
example:

class BookCollection(DocumentCollection):
    model = Book
    name = "books"
    included_relations = [
        'publisher', 'publisher/links', 'publisher/tags', 'extra_info',
        'chapters', 'authors', 'tags', 'categories']
    excluded_fields = [
        'authors/email', 'summary']

The tool uses these documents to watch for updates to certain
relationships. That’s why, in this case, I want to view the chapter
relationship change from a Book-centric perspective.

Thanks again for all the help.

chad.
​

-- 
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