Created
November 28, 2018 15:56
-
-
Save Eth3rnit3/2427b7268bc19c1fdaa333e1b520d1d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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