Sir, your association method is totally different from documented: http://sequelizejs.com/docs/latest/associations
So, if you want to run with associations I can recommend you to follow the instructions.
The first thing is to split models definitions and establishing associations, since to make association you need all the models to be defined already. If you trying to define association in the same file, where model defined – you might fall in error when one of associated model is not defined yet.
If your model definition is written in
db.Candidate
variable you should to use exactly this variable name when establishing association. And to make associated models be well retrieved (or saved) on beautiful automatically created methods, you need to use parameteras
while defining.dbCandidate.hasOne( db.Role, {as: 'Role'} )
Any model associations are bidirectional. It mean you have to define not only
db.Role.hasMany( db.Candidate, {as: 'Candidate'}
butdb.Candidate.hasOne( db.Role, {as: 'Role'} )
aslo.