[PonyORM-list] Trying to model friendships and getting ERDiagramError

Tomislav Tustonic ttustonic at outlook.com
Sun Oct 12 19:55:08 UTC 2014


Martin Frlin wrote:
> Those are my models:
>
> class User(db.Entity):
>      name = PrimaryKey(str)
>
> class Friendship(db.Entity):
>      user1 = Required(User)
>      user2 = Required(User)
>      PrimaryKey(user1, user2)
>
> when calling db.generate_mapping() I get this error:
> pony.orm.core.ERDiagramError: Reverse attribute for Friendship.user1 not found
>
> What am I doing wrong?
>
It means that you have to specify the other end of the relationship. So, your 
User needs something
like
    friends = Set('Friendship')
But, since you have multiple relationships between User and Friendship, you'll 
have to provide 'reverse' parameter, so finally you'll need something like this:

class User(db.Entity):
     name = PrimaryKey(str)
     friendsaccepted = Set(lambda: Friendship, reverse='user1')
     acceptedby = Set(lambda: Friendship, reverse='user2')

class Friendship(db.Entity):
     user1 = Required(User)
     user2 = Required(User)
     PrimaryKey(user1, user2)

See more here:
http://doc.ponyorm.org/relationships.html


HTH, Tom


More information about the ponyorm-list mailing list