peewee backref和多选

时间:2019-04-03 15:28:05

标签: peewee flask-peewee

我有两个表:

class Video(MyBaseModel):
    videoid = CharField(default="",index=True)
    title = CharField(default="")
    description = CharField(default="")
    mainguy = ForeignKeyField(MainOne,backref='posts')

class Other(MyBaseModel):
    videoid = CharField(default="",index=True)
    title = CharField(default="")
    description = CharField(default="")
    score ....

(请注意,我没有显示MainOne,因为它只有一个名称字段。 在Flask网站上,我试图从“帖子”中获取Video + Other。

tg = MainOne.get(MainOne.id == my_id)
videos = tg.posts.select(Video,Other).join(Video,on=(Video.videoid==Other.videoid)).order_by(Other.score.desc())

如果我调试代码print(videos.sql()),则会看到一个奇怪的查询:

('SELECT "Other" AS "t1", "video" AS "t2" FROM "Other" AS "t1" INNER JOIN "video" AS "t2" ON ("t2"."videoid" = "t1"."videoid") WHERE ("t1"."id" = ?) ORDER BY "t1"."score" DESC', [2])

如何从视频和其他字段中选择所有字段?我应该全部输入吗?如果我尝试选择(Other.title,Video.title),则可以。

0 个答案:

没有答案