Skip to content

Instantly share code, notes, and snippets.

@Eth3rnit3
Created November 28, 2018 15:56
Show Gist options
  • Save Eth3rnit3/2427b7268bc19c1fdaa333e1b520d1d6 to your computer and use it in GitHub Desktop.
Save Eth3rnit3/2427b7268bc19c1fdaa333e1b520d1d6 to your computer and use it in GitHub Desktop.
const models = require('./models');
const User = models.User;
const Company = models.Company;
const WorkingDay = models.WorkingDay;
// 1:1
// Get the company linked to a given User
User.findOne({
where: {email: '[email protected]'}, include: 'company'
})
.then((findedUser) => {
// Get the User with Company datas included
console.log(findedUser)
// Get the company record only
// console.log(findedUser.company)
})
.catch((err) => {
console.log("Error while find user : ", err)
})
// 1:N
// Get the employees for a given company
Company.findByPk(1, {include: ['employes']})
.then((company) => {
// Get the Company with Users (employes) datas included
console.log(company)
// Get the Users (employes) records only
// console.log(company.get().employes)
})
.catch((err) => {
console.log("Error while find company : ", err)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment