我想显示我的自定义字段“位置”与多对多的关系。
桶
id | fk_language_id |代码
阻止
id |代码
Bucket_Block
id | fk_bucket_id | fk_block_id |位置
schema.js
# Bucket
type Bucket {
id: Int!,
code: String
language(id: Int): Language
blocks: [Block]
}
# Block
type Block {
id: Int!,
code: String,
is_active: Boolean,
position: Int
}
# query for types
type Query {
buckets: [Bucket]
}
resolvers.js
Bucket: {
blocks(bucket) {
return bucket.getBlocks();
}
},
connectors.js
// define bucket
const BucketModel = db.define('bucket', {
code : {type: Sequelize.STRING},
is_active: {type: Sequelize.BOOLEAN}
});
// define block
const BlockModel = db.define('block', {
code : {type: Sequelize.STRING},
is_active: {type: Sequelize.BOOLEAN}
});
// define bucket_block
const BucketBlockModel = db.define('bucket_block', {
position: {type: Sequelize.INTEGER}
});
BucketModel.belongsToMany(BlockModel, {
through : 'bucket_block',
foreignKey: 'fk_bucket_id'
});
BlockModel.belongsToMany(BucketModel, {
through : 'bucket_block',
foreignKey: 'fk_block_id'
});
我尝试添加数据透视表:架构中的Int,但字段没有
“位置”:空