![]() |
REST validationRules - 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: REST validationRules (/showthread.php?tid=76748) |
REST validationRules - florincm - 06-15-2020 Hello, I'm giving v4 a try after loving v3 for a long time. I'm really impressed by the new REST features built in but i have a problem. (or lack of knowledge) If i have a following validation rules in my model: PHP Code: <?php This works great for inserts but i get the is_unique error when I try to do an update, luckily theres a feature to feature to fix that PHP Code: is_unique[companies.company_number,company_number,{company_number}] But then insert breaks with a mysql error Code: Duplicate entry '77777777' for key 'company_number' Is there a way to easily fix this or have different validation rules for the 2 different requests ? something like this maybe ? PHP Code: protected function beforeUpdate(array $data){ RE: REST validationRules - snelledre - 06-16-2020 Best, Use "id" as primary key and Company_number leave as it is. But lookout change also you're migration or direct your database table. Then you can use is_unique[companies.company_number,id,{id}] For example. Code: <?php RE: REST validationRules - florincm - 06-16-2020 not exactly what i wanted but it works, thanks. |