SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.21k stars 662 forks source link

can't find belongsToMany Table inputFrom in admin-bro #676

Closed joon610 closed 3 years ago

joon610 commented 3 years ago

Describe the bug

  1. make belongsToMany Table in sequelize.
    db.Post.belongsToMany(db.Student, {  through: 'StudentClass'});
    db.Student.belongsToMany(db.Post, { through: 'StudentClass' });
  2. can't find input Form in Admin-bro

Installed libraries and their versions "@admin-bro/express": "^3.0.1", "@admin-bro/sequelize": "^1.1.1", "admin-bro": "^3.3.1", "admin-bro-expressjs": "^2.1.1", "admin-bro-sequelizejs": "^0.5.1",

To Reproduce Steps to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen.

Screenshots

스크린샷 2020-11-06 오후 4 11 30

AdminBroOptions with schema ` //post.js const DataTypes = require('sequelize'); const { Model } = DataTypes;

module.exports = class Post extends Model { static init(sequelize) { return super.init( { content: { type: DataTypes.TEXT, allowNull: true, },

  },
  {
    modelName: 'Post',
    tableName: 'posts',
    charset: 'utf8mb4',
    collate: 'utf8mb4_general_ci'
    sequelize,
  }
);

} static associate(db) { db.Post.belongsToMany(db.Student, { through: 'StudentClass', }); } };

//student.js const DataTypes = require('sequelize'); const { Model } = DataTypes;

module.exports = class Student extends Model { static init(sequelize) { return super.init( { name: { type: DataTypes.STRING(30), allowNull: false, unique: true, }, }, { modelName: 'Student', tableName: 'students', charset: 'utf8', collate: 'utf8_general_ci', sequelize, } ); } static associate(db) { db.Student.belongsToMany(db.Post, { through: 'StudentClass' }); } };

` Desktop (please complete the following information if relevant):

Smartphone (please complete the following information if relevant):

Additional context Add any other context about the problem here.

artureg commented 3 years ago

working solution

sequelize.define('decks_to_users', {
    id: {
        type: Sequelize.INTEGER,
        autoIncrement: true,
        primaryKey: true
    },
    userId: {
        type: Sequelize.INTEGER,
        references: {
            model: db.User,
            key: 'id',
        },
    }, deckId: {
        type: Sequelize.INTEGER,
        references: {
            model: db.Deck,
            key: 'id',
        },
    },
}, {timestamps: false});

db.User.belongsToMany(db.Deck, {through: 'decks_to_users'})
db.Deck.belongsToMany(db.User, {through: 'decks_to_users'})
joon610 commented 3 years ago

thank you comment!