Describe the bug
When updating a discount through an API, it throws an error related to SQL:
"SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`homestead`.`discount_reward_products`, CONSTRAINT `discount_reward_products_discount_reward_id_foreign` FOREIGN KEY (`discount_reward_id`) REFERENCES `discount_rewards` (`id`)) (SQL: delete from `discount_rewards` where `discount_rewards`.`discount_id` = 5 and `discount_rewards`.`discount_id` is not null)"
To Reproduce
- Create a discount, fx:
this.$getcandy.on('discounts', 'postDiscounts',
{
name: {
en: 'Buy one get none free',
da: 'Buy one get none free'
},
start_at: '2019-06-04T14:27:02.000Z',
end_at: '2019-06-04T14:27:02.000Z'
})
- Get status
201
- Get the discount ID from server response (fx.
wz6d39dj
).
- Update discount, fx:
this.$getcandy.on('discounts', 'putDiscountsDiscountId', 'wz6d39dj', {
start_at: '2019-08-24T14:15:22Z',
end_at: '2022-08-24T14:15:22Z',
priority: 0,
stop_rules: true,
status: true,
attribute_data: {
name: {
webstore: {
da: 'Buy one get none free',
en: 'Buy one get none free'
}
}
},
channels: {
data: {
id: 1,
published_at: '2021-06-14T14:15:22Z'
}
},
rewards: {
data: {
products: [
{
product_id: 24202,
quantity: 1
}
]
}
},
sets: {
data: [
{
scope: 'string',
outcome: true,
items: {
data: [
{
eligibles: [
'string'
],
type: 'string'
}
]
}
}
]
}
})
- See error in the server response.
Expected behavior
Server returns a response with status 200.