v[4] belongsToMany - attach() - invalid input syntax for type uuid: "" #1757
-
Not sure why Im getting this error: The
Pivot Table: this.create('customer_promotion', (table) => {
table.uuid('id').primary()
table.uuid('tenant_id')
table.uuid('customer_id')
table.uuid('promotion_id')
table.string('assigned_by')
table.timestamps()
})
Promotion Model: class Promotion extends Model {
...
customers() {
return this
.belongsToMany('App/Models/Customer')
.withPivot(['created_at', 'assigned_by', 'id'])
.pivotModel('App/Models/CustomerPromotion')
}
...
}
module.exports = Promotion
CustomerPromotion Model: const uuid = use('uuid/v4')
class CustomerPromotion extends Model {
static get table () {
return 'customer_promotion'
}
static boot() {
super.boot()
this.addHook('beforeCreate', async (instance) => {
instance.id = uuid.v4()
})
}
static get incrementing() {
return false
}
}
module.exports = CustomerPromotion
SomeController.js: ...
await promotion.customers().attach(customerIdArray, (row) => {
row.assigned_by = `${first_name} ${last_name}`
row.created_at = moment().format('YYYY-MM-DD')
})
...
Update: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi, Anyone can help me with this? |
Beta Was this translation helpful? Give feedback.
-
Okay I wasted a few hours in this lmao, nothing wrong with the |
Beta Was this translation helpful? Give feedback.
Okay I wasted a few hours in this lmao, nothing wrong with the
attach()
.I just debugged that one item on the array I'm passing on
attach()
is just an empty string.hence the error
invalid input syntax for type uuid: ""