MappingError for self-referenced entities in a many-to-many relationship #75

Closed
crazygolem opened this Issue Sep 25, 2014 · 1 comment

Projects

None yet

2 participants

@crazygolem

The following entities make Database.generate_mapping raise a MappingError:

class DGVertex(db.Entity):
    id = PrimaryKey(int, auto=True)
    previous = Set("DGVertex", reverse="next")
    next = Set("DGVertex", reverse="previous")
class ClusterNode(db.Entity):
    id = PrimaryKey(int, auto=True)
    related = Set("ClusterNode")

The problem arises when both end of the relation are a Set. In the next example (a small variation of DGVertex where one end of the relation is not a Set), the problem does not arise:

class TreeNode(db.Entity):
    id = PrimaryKey(int, auto=True)
    parent = Optional("TreeNode", reverse="children")
    children = Set("TreeNode", reverse="parent")

Note that all classes used as example have been generated using Pony's Diagram Editor. There is no problem to design them using the "Designer" tab, and Python code is properly generated.

@kozlovsky kozlovsky closed this in 73e100a Oct 3, 2014
@kozlovsky kozlovsky added the bug label Oct 3, 2014
@kozlovsky kozlovsky self-assigned this Oct 3, 2014
@kozlovsky
Contributor

Should be fixed now

@kozlovsky kozlovsky added a commit that referenced this issue Oct 8, 2014
@kozlovsky kozlovsky Pony ORM Release Candidate 0.6rc1
http://blog.ponyorm.com/2014/10/08/pony-orm-0-6-release-candidate-1

# New features:

* Python 3 support
* pymysql adapter support for MySQL databases

# Backward incompatible changes

Now Pony treats both `str`` and `unicode`` attribute types as they are unicode strings in both Python 2 and 3. So, the attribute declaration `attr = Required(str)` is equal to `attr = Required(unicode)` in Python 2 and 3. The same thing is with `LongStr` and `LongUnicode` - both of them are represented as unicode strings now.

For the sake of backward compatibility Pony adds `unicode` as an alias to `str` and `buffer` as an alias to `bytes` in Python 3.

# Other changes and bug fixes

* Fixes #74: Wrong FK column type when using sql_type on foreign ID column
* Fixes #75: MappingError for self-referenced entities in a many-to-many relationship
* Fixes #80: “Entity NoneType does not belong to database” when using to_dict
395036b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment