On Fri, Jul 21, 2017 at 11:40 AM, Nathan Mooth <nat.d.mo...@gmail.com> wrote: > So I have a tree-like data structure that I need to store in a way so that I > can see all children or all parents of a query as well as their relative > depth from the query item. In the past I have been using the closure table > method demonstrated in this blog post, however now that I am switching to > sqlAlchemy I am wondering if there is a better way to do this. So basically > I am trying to figure out how to run a series of inserts on my closure table > whenever an item is added to the main table, as well as what would be the > best way to load the child or parent items of a query.
you'd likely want to use the same approaches illustrated in the nested sets example at http://docs.sqlalchemy.org/en/latest/_modules/examples/nested_sets/nested_sets.html - basically intercept before_insert(), or after_insert(), the run the additional SQL you need on the given connection within the flush process. The query approach is also illustrated there. If you're just going for in-memory, "load a node, then access node.children", and you don't need elaborate cross-depth searching and set operations, then all of these approaches are far too complicated, just use adjacency list. > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > 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 https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.