Welcome Guest, Not a member yet? Register   Sign In
Custom Rule works in insert but fails in update
#1

Hello, 
I have written a custom rule to check if a "slug" is unique. The "slug" text field must be unique for a single tenant, so I have to check both parameters. 
PHP Code:
$data['tenant_id']
$data['slug'


By using this new rule in my model (following the doc), everything works well during the insert ... but if the tenant wants to update the slug field of one of his records, it fails.

Inside the rule, the $data['tenant_id'] is missing because the tenant_id is not changed so it was not included in the $data array.

Can I add the tenant_id (or other fields if needed) to the custom rule, even if that field it's not changed?
Reply
#2

Try to call cleanRules(false) before the update.
See https://codeigniter4.github.io/CodeIgnit...ationrules
Reply
#3

(10-20-2022, 06:47 PM)kenjis Wrote: Try to call cleanRules(false) before the update.
See https://codeigniter4.github.io/CodeIgnit...ationrules



GREAT! Solved. Thank you.
Reply
#4

Good!
You are in luck. This feature has just been fixed to work in v4.2.7.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB