uralbash / sqlalchemy_mptt

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

tree_id is incorrectly set to an existing tree if no parent is set #23

Closed GaretJax closed 10 years ago

GaretJax commented 10 years ago

This line https://github.com/ITCase/sqlalchemy_mptt/blob/master/sqlalchemy_mptt/events.py#L65 should probably be something along the lines of:

tree_id = connection.scalar(select([func.max(table.c.tree_id) + 1])) or 1

Right now, the first parentless item is inserted with a tree_id of 1, but from the second on they are all set to 2.