How can I have an extra column in postgres with sailsjs model association?
This is an example of my two models
// Users.js attribute
...
challenges: {
collection: 'challenge',
via: 'userChallenge'
}
// Challenge.js attribute
...
userChallenge: {
collection: 'users',
via: 'challenges'
}
...
With this I get the table association (many to many)
id | challenge_userChallenge | users_challenges
I need one or more extra columns like "active" or something like that
Thanks in advance
You should use through associations.
Let's take the
PostandTagmodels as an example. ThePosthas and belongs to manyTagand theTaghas and belongs to manyPost. These two models will be joined via thePostTagmodel.Our
Postmodel:Our
Tagmodel:Our
PostTagmodel (we're creating it manually, we don't want Sails.js to create it automatically):The
PostTagmodel is actually the join table. In this model, you can define your extra fields.Hope this helps.