Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user.getCompanies #17

Open
eliecer2000 opened this issue Nov 15, 2018 · 1 comment
Open

user.getCompanies #17

eliecer2000 opened this issue Nov 15, 2018 · 1 comment

Comments

@eliecer2000
Copy link

Greetings, I really like your application, in fact I have learned a lot with the details of your explanation, but there is a function that I can not find, or I do not know where it comes from. and for future consultations of other tables know how to implement them.

[err, companies] = await to(user.getCompanies({include: [ {association: Company.Users} ] }));
where “user.getCompanies” came from

Excuse my english, I’m supporting myself in google. Thank you.

@RochMoreau
Copy link

Hi ! Did you found the answer by yourself ?
The getCompanies() function is defined by Sequelize, it is used to request datas from foreign key in the database. In your user.model.js you have

Model.associate = function(models){
        this.Companies = this.belongsToMany(models.Company, {through: 'UserCompany'});
    };

Using user.getCompanies() will return you a promise from which you can get all the companies linked to the user user.

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants