Skip to content

BelongsToMany using others field #38

Open
@danielsalles

Description

@danielsalles

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions