0

I'm working on a new project and I'm facing this problem;

So let's say in sequelize the tables User and Project are defined.

In the DB, there is a third table ProjectsUsers, and I need to fetch from that.

This table only has columns like userId, createdAt, updatedAt, which are the default ones, so the table isn't defined in the model.

Should I define it (as an empty table) in the model (not sure if it would break things or not, but seems unlikely to work).

How can I query that table?

1 Answer 1

0

Just define a table with right association and you will be able to query on it.

For example:

var UserModel = sequelize.define('user', {},{});
var ProjectModel = sequelize.define('project', {}, {});
var ProjectsUsersModel = sequelize.define( 'ProjectsUsers', {}, {} );

UserModel.hasMany( ProjectModel );
ProjectModel.hasMany( UserModel )
CourseTopics.belongsTo( topicModel ).belongsTo( ProjectModel );

ProjectsUsersModel.findAll({include:[UserModel, ProjectModel]})
.success(function(projectsUsers) {
 });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.