uralbash / sqlalchemy_mptt

SQLAlchemy nested sets mixin (MPTT)
http://sqlalchemy-mptt.readthedocs.io
MIT License
196 stars 32 forks source link

drilldown_tree as a list #74

Closed RomanSarnov closed 2 years ago

RomanSarnov commented 3 years ago

How i can get all children recursive as base query sqlalchemy?

uralbash commented 3 years ago

You can run clean sqlalchemy request

level           Nested sets example
1                    1(1)22       ---------------------
        _______________|_________|_________            |
       |               |         |         |           |
2    2(2)5           6(4)11      |      12(7)21        |
       |               ^         |         ^           |
3    3(3)4       7(5)8   9(6)10  | 13(8)16   17(10)20  |
                                 |    |          |     |
4                                | 14(9)15   18(11)19  |
                                 |                     |
                                  ---------------------

        query = query.filter(table.tree_id == 1)\
            .filter(table.left >= 12)\
            .filter(table.right <= 21)

or use the method from the library

https://sqlalchemy-mptt.readthedocs.io/sqlalchemy_mptt.html#sqlalchemy_mptt.mixins.BaseNestedSets.drilldown_tree