uralbash / sqlalchemy_mptt

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

Incompatibility with Django MPTT: level value for root node #56

Closed elephantum closed 7 years ago

elephantum commented 7 years ago

Currently Django MPTT assigns level=0 to root nodes, while sqlalchemy_mptt assigns level=1 http://django-mptt.readthedocs.io/en/latest/technical_details.html?highlight=level#level

In our case we have to work with datastructures created in Django from Airflow/SQLAlchemy pipeline. level incompatibility makes it impossible to rely on filtering by level value to find all nodes at given depth.

Are you willing to consider changing starting value of level from 1 to 0 to improve compatibility with Django MPTT?

uralbash commented 7 years ago

I made the changes that allow this, could you check your case on version from master branch (0.2.2-pre0).

If everything is ok then I will release it.


class TreeWithCustomLevel(Base, BaseNestedSets):
    __tablename__ = "tree_custom_level"

    id = Column(Integer, primary_key=True)
    visible = Column(Boolean)

    sqlalchemy_mptt_default_level = 0

    def __repr__(self):
        return "<Node (%s)>" % self.id
uralbash commented 7 years ago

@elephantum You can get it from PyPi now.

elephantum commented 7 years ago

Cool, thanks!

blueyed commented 5 years ago

How is the compatibility in general? I think it would be worth adding a note to the docs in this regard (where django-mptt is mentioned already).