trailsjs / trailpack-sequelize

:package: Sequelize.js Trailpack http://sequelizejs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BelongsToMany using others field

danielsalles opened this issue · comments

I'm trying to add a new field associate n: m, but it is not working.

Tounament model simple:

module.exports = class Tournament extends Model {

  static config () {
    return {
      store: 'mysql',
      options: {
        classMethods: {
          associate: models => {
            models.Tournament.hasMany(models.Awards)
            models.Tournament.belongsToMany(models.User, { through: 'organizer' })
          }
        }
      }
    }
  }

User model simple:

module.exports = class User extends Model {

  static config () {
    return {
      store: 'mysql',
      options: {
        classMethods: {
          associate: models => {
            models.User.belongsToMany(models.Tournament, { through: 'organizer' })
          }
        }
      }
    }
  }

Organizer complet:

'use strict'

const Model = require('trails/model')

/**
 * @module Organizer
 * @description Organizers tournaments
 */
module.exports = class Organizer extends Model {

  static config () {
    return {
      store: 'mysql'
    }
  }

  static schema (app, Sequelize) {
    return {
      permission: { type: Sequelize.STRING, allowNull: false, defaultValue: 'support' }
    }
  }
}

This permission field is not appearing in my database.