Custom Rule works in insert but fails in update - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Custom Rule works in insert but fails in update (/showthread.php?tid=84193) |
Custom Rule works in insert but fails in update - Jag81 - 10-20-2022 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'] 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? RE: Custom Rule works in insert but fails in update - kenjis - 10-20-2022 Try to call cleanRules(false) before the update. See https://codeigniter4.github.io/CodeIgniter4/models/model.html#cleanvalidationrules RE: Custom Rule works in insert but fails in update - Jag81 - 10-21-2022 (10-20-2022, 06:47 PM)kenjis Wrote: Try to call cleanRules(false) before the update. GREAT! Solved. Thank you. RE: Custom Rule works in insert but fails in update - kenjis - 10-21-2022 Good! You are in luck. This feature has just been fixed to work in v4.2.7. |