I have three tables contractors, projects and jointable for these two is projects_contractors and i created models and wrote a relation like below,
Contractor.hasMany(Project, {joinTableName: 'projects_contractors'})
Project.hasMany(Contractor, {joinTableName: 'projects_contractors'})
I want to access this Contractor based projects means inner JOIN.
Core query : select c.id,c.name,p.id,p.name from contractors c inner join projects_contractors pc on c.id=pc.contractor_id inner join projects p on p.id = pc.project_id
I was failed in implementing the below code. "required" is a keyword which used for inner JOIN but not working if we keep.
Contractor.findAll({ include: [Project, {required: false}]}).success(function(list){
console.log("hi")
res.send(204)
})
If not keeping required it will creates a left outer JOIN on projects and contractors. Suggest me with a sample example for the above senario.
The correct syntax is:
Contractor.findAll({ include: [{model: Project, required: true}]})
Generally the include params take either a model, or an object with a model parameter and optional as/required/include/where params.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With