Search code examples
pythonmysqljoinpeewee

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."


Solution

  • Provide a join condition

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

    Here you should replace AppCompanyID and AppCompanyToIndustryID with proper column