Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
Force database tablename for collection relationship in Sails

In a sails project, considering a model User and a model Role, with a relationship between User and Role :

// `User.js
module.exports = {

    attributes: {

        ...

        roles: {
            collection: 'role',
            dominant: true
        },

        ...
    }
}

For the the database representation, sails/waterline will create following tables :

  • table user,
  • table role,
  • table like user_roles__role_roles_role to represent the collection

I know we can force the name for the models USER and ROLE (with the property 'tablename' : http://sailsjs.com/documentation/concepts/models-and-orm/attributes).

But how can we force the name the relationship table ? (Especially this name is quite long and tends to exceed limit).

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Assuming this is a two-way relationship, and the Role model has a users collection, Sails will expect a table named role_users__user_roles, which has the role id first, user id second.

Your example table name would require User to be dominant and would require the Role model to have an attribute named roles_role that is a User collection.

To create your own join table, you can use the through association method and add a new model that represents the relationship, perhaps UsersRoles, and specify the tableName in that model definition.

Examples of the through association:

  • sails docs
  • similar question
  • gist from comments in that question
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!