python - How to select records in the case of a many to many relation with ponyorm -
i new ponyorm.
suppose have these 2 classes , many-to-many relation among them:
class student(db.entity): id = primarykey(str) name = required(str) courses = set("course") class course(db.entity): id = primarykey(str) name = required(str) semester = required(int) students = set(student)
and want select courses followed particular student. is:
student = student.select(lambda s: s.id == id).get() courses = course.select(lambda c: c.students == student).get()
and error:
incomparable types 'set of student' , 'student' in expression: c.students == student
what correct way this? thanks
i don't know exact library think issue c.students
specifies set of students testing equality doesn't make sense.
you might want change second line (i didn't test though):
course.select(lambda c: student in c.students).get()
this leaves me wondering if there better way this. if trying retrieve courses specific students attends why don't retrieve courses
field variable student
?
something like
student = student.select(lambda s: s.id == id).get() student.courses #
Comments
Post a Comment