使用 ponyorm 检查 PrimaryKey 是否存在
Check if PrimaryKey exists with ponyorm
我正在尝试使用 pony orm 查看主键是否存在。我已经走到这一步了,但它总是会引发错误。
class Favorite(db.Entity):
game = Required(Game)
user = Required(User)
date_favorited = Required(datetime)
PrimaryKey(user, game)
这是函数
if Favorite.get(lambda: user, game) is not None:
favorited = 1
这是错误
TypeError: The second positional arguments should be globals dictionary. Got: Game[12]
中得到了帮助
if Favorite.exists(user=x, game=y):
favorited = 1
我正在尝试使用 pony orm 查看主键是否存在。我已经走到这一步了,但它总是会引发错误。
class Favorite(db.Entity):
game = Required(Game)
user = Required(User)
date_favorited = Required(datetime)
PrimaryKey(user, game)
这是函数
if Favorite.get(lambda: user, game) is not None:
favorited = 1
这是错误
TypeError: The second positional arguments should be globals dictionary. Got: Game[12]
if Favorite.exists(user=x, game=y):
favorited = 1