Redis is by nature a key value data store. It is not a relational database like SQL.
Therefore, Popoto may not be ideal for highly relational data because the query interface is very limited.
Review the features below before using
from popoto import Model, KeyField, Relationship class Person(Model): name = KeyField() class Group(Model): name = KeyField() class Membership(Model): member = Relationship(model=Person) group = Relationship(model=Group)
sally = Person.create(name="Sally") friends = Group.create(name="My Line Friends") Membership.create(member=sally, group=friends) memberships = Membership.query.filter(member__name="Sally", group=friends_group) print(memberships.member) > Sally
When writing a query, start with the model you want returned and use filter params. In the above example, to get all the memberships of a group, use a query like this:
memberships = Membership.query.filter(group=friends_group)
To traverse relationships, use a list expansion like this:
friends = [m.person for m in Membership.query.filter(group=friends_group)]