Node.js AdonisJS V4-belongToMany-sync()/attach()-类型uuid的输入语法无效:“0”&引用;
不确定我为什么会出现此错误:Node.js AdonisJS V4-belongToMany-sync()/attach()-类型uuid的输入语法无效:“0”&引用;,node.js,pivot-table,has-and-belongs-to-many,adonis.js,Node.js,Pivot Table,Has And Belongs To Many,Adonis.js,不确定我为什么会出现此错误:类型uuid的输入语法无效:“” beforeCreatehook事件起作用,并插入列ID,但我仍然得到那个奇怪的错误。 这里有我遗漏的东西吗 数据透视表: this.create('customer\u promotion',(表)=>{ 表.uuid('id').primary() 表.uuid('tenant_id')) 表.uuid('customer\u id') 表.uuid('promotion\u id') table.string('assigne
类型uuid的输入语法无效:“”
beforeCreate
hook事件起作用,并插入列ID,但我仍然得到那个奇怪的错误。
这里有我遗漏的东西吗
数据透视表:
this.create('customer\u promotion',(表)=>{
表.uuid('id').primary()
表.uuid('tenant_id'))
表.uuid('customer\u id')
表.uuid('promotion\u id')
table.string('assigned_by')
表1.timestamps()
})
促销模式:
类升级扩展了模型{
...
客户(){
还这个
.belongtomany('应用程序/模型/客户')
.withPivot(['created_at','assigned_by','id'])
.pivotModel('App/Models/CustomerPromotion'))
}
...
}
module.exports=促销
客户促销模式:
const uuid=use('uuid/v4')
类CustomerPromotion扩展了模型{
静态get表(){
返回“客户推广”
}
静态启动(){
super.boot()
this.addHook('beforeCreate',async(instance)=>{
instance.id=uuid.v4()
})
}
静态获取递增(){
返回错误
}
}
module.exports=CustomerPromotion
SomeController.js:
。。。
等待促销。customers().sync(CustomerDarray,(行)=>{
row.assigned_by=`${first_name}${last_name}`
row.created_at=moment().格式('YYYY-MM-DD')
})
...
更新:
另一件奇怪的事情是,即使我有一个错误并且UUID被插入,它仍然被存储
请参见下面的屏幕截图:
好的,我在这个lmao上浪费了几个小时,
attach()
没有问题。
我刚刚调试了我正在传递的数组attach()
上的一个项只是一个空字符串。
因此,对于类型uuid:“