PonyORM reverse attribute not found error only on one class

81 Views Asked by At

I have three table as follow:

class User(db.Entity):
    _table_ = "tbl_user"
    idUser = PrimaryKey(uuid.UUID,default = uuid.uuid4 ,column = 'id_user')
    username = Required(str, unique = True)
    email = Required(str, unique = True)
    password = Required(str)
    name = Optional(str,nullable = True)
    gender = Optional(str, nullable = True)
    address = Optional(str,nullable = True)
    birth = Optional(date, nullable = True)
    phoneNumber = Optional(str, column = "phone_number",nullable = True)
    dateRegister = Required(date,column = 'date_register')
    picture = Optional(str, nullable = True)
    isActivated = Required(bool)
    article = Set('Article')
    comment = Set('Comment')
    like = Set('Like')
class Article(db.Entity):
    _table_ = "tbl_article"
    idArticle = PrimaryKey(uuid.UUID,default=uuid.uuid4,column = 'id_article')
    comment = Set('Comment')
    like = Set('Like')
    articleTag = Set('ArticleTag')
    articleCategory = Set('ArticleCategory')
    user = Required(User,column = 'id_user')
    content = Required(Content,column = 'id_content')
class Friend(db.Entity):
    _table_ = "tbl_friend"
    userOne = Required(User,column="id_user_one")
    userTwo = Required(User,column="id_user_two")
    dateFriend = Required(datetime,column="date_friend")

When db.generate_mapping() is executed, it throws the following error

pony.orm.core.ERDiagramError: Reverse attribute for Friend.userOne not found

When class Friend is removed, the error goes away. I don't understand, why can class Article use User id_user column as foreign key while class Friend throws the reverse attribute error ? What causes this problem and how to fix it ?

1

There are 1 best solutions below

0
LLL On

Found the answer at Reverse attribute not found in PonyORM. I had to add Set() attribute to User class. By adding the following to User class

friendUserOne = Set('Friend', reverse="userOne")
friendUserTwo = Set('Friend', reverse="userTwo")

The problem is fixed. I don't understand why this is a thing in PonyORM, maybe i will look more into this later.