sails.jssails-mssqlserver

Sailsjs Waterline many to many relationship with legacy database


I have 2 domain User and Role and it has a relation to Many To Many. User has many Roles. When I run the application it creates the mapping table like role_user__user_role. I need to support legacy database where the table name is UserRole. Can anyone help me what I need to do to achieve the same?

User.js has an attribute like:

role: {
  collection: 'role',
  via: 'user'
}

and Role.js has an attribute like:

user: {
  collection: 'user',
  via: 'role'
}

Solution

  • You can use through associations, see here.