Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda