Thursday, 27 April 2017

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).



via arnaud del.

No comments:

Post a Comment