Alexander Alexander - 5 months ago 65
SQL Question

how to make join after where condition with peewee

Is that possible making join after where condition like that

query = (AppCompany
.select(AppCompany,User)
.join(User)
.where(AppCompany.status_id==request.args.status_id)
)

if request.args.industry:
query = query.switch(AppCompany).join(AppCompanyToIndustry)
query = query.where(AppCompanyToIndustry.industry_id==request.args.industry)


I tired but it throwed this error : "ValueError: A join condition must be specified."

Answer

Provide a join condition

query = query.switch(AppCompany)
             .join(AppCompanyToIndustry)
             .where(AppCompanyID == AppCompanyToIndustryID)

Here you should replace AppCompanyID and AppCompanyToIndustryID with proper column