[英]Join 3 table in peewee
I want to be able to join multiple tables in peewee. 我希望能够在peewee中加入多个表。 the scenario is a little difficult for me to figure out how to get it to work with peewee. 这种情况对我来说很难弄清楚如何使其与peewee一起使用。 I have the following tables: user,product,images 我有下表:用户,产品,图像
this is my models: 这是我的模型:
class user(BaseModel):
id = AutoField(primary_key=True)
username = CharField()
password = CharField()
class product(BaseModel):
id = AutoField(primary_key=True)
id_user = ForeignKeyField(user)
product_name = CharField()
product_price = IntegerField()
product_description = TextField()
class images(BaseModel):
id = AutoField(primary_key=True)
id_product = ForeignKeyField(barang)
image_name = TextField()
i want the output like this product.id,user.username,product.product_name,product.price,product.product_description,images.image_name 我想要类似product.id,user.username,product.product_name,product.price,product.product_description,images.image_name的输出
query = (Product
.select(Product, User, Image)
.join_from(Product, User)
.join_from(Product, Image))
for product in query:
print(product.product_name)
print(product.id_user.username)
print(product.images.image_name)
This is all documented very thoroughly here: http://docs.peewee-orm.com/en/latest/peewee/relationships.html 此处对此进行了非常详尽的记录: http : //docs.peewee-orm.com/en/latest/peewee/relationships.html
Please read the docs. 请阅读文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.