monetizeio / sqlalchemy-orm-tree

An implementation for SQLAlchemy-based applications of the nested-sets/modified-pre-order-tree-traversal technique for storing hierarchical data in a relational database.
Other
54 stars 10 forks source link

Issues when primary column name differs from mapper attribute name #25

Open miracle2k opened 9 years ago

miracle2k commented 9 years ago

I have this in a node:

id = Column('page', Integer, primary_key=True)

That is, the name in the database is "page", but the name in the mapper is "id". This is not handled right:

  File "/Users/michael/Development/checkouts/sqlalchemy-orm-tree/sqlalchemy_tree/orm.py", line 116, in before_insert
    self._reload_tree_parameters(connection, node, target)
  File "/Users/michael/Development/checkouts/sqlalchemy-orm-tree/sqlalchemy_tree/orm.py", line 59, in _reload_tree_parameters
    node_pk = getattr(node, options.pk_field.name)
AttributeError: 'Page' object has no attribute 'page'