Set symbol in rule is_unique - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29) +--- Thread: Set symbol in rule is_unique (/showthread.php?tid=76246) |
Set symbol in rule is_unique - 5flex - 04-25-2020 At the moment, we have hard-coded code in the Validation file, for the is_unique function: PHP Code: if (! empty($ignoreField) && ! empty($ignoreValue)) Everything seems to be fine, but there is a problem. What if I want to check for uniqueness, but I need to use not "!=" but just the symbol "=". As an example. I make a tree of product categories and created 2 categories "Cell Phones" and "Home Appliances." I want to add a subcategory to each of them, for example, "Samsung", but make it inside the subcategory unique. Now it’s impossible to do this, because by applying the is_unique[categories.name, sub_id, {id}] rule, ALL the table in the database will be checked! In my case, the validation rule will always be like this: PHP Code: SELECT 1 FROM categories WHERE name = 'Samsung' AND sub_id != 5 (as an example) But in order for it to work, I need to change the condition for verification on: PHP Code: SELECT 1 FROM categories WHERE name = 'Samsung' AND sub_id = 5 (check field ONLY IN SUBCATEGORY!!! ) This is now impossible to do. I suggest making changes to the creation of the function so that you can set the condition yourself. As an example: PHP Code: is_unique[categories.name, sub_id=, {id}] or PHP Code: is_unique[categories.name, sub_id,'=', {id}] RE: Set symbol in rule is_unique - php_rocs - 04-25-2020 @5flex, Why don't you make the is_unique function smarter. Is there a criteria that can help you determine which condition to use? Can you add a optional criteria to the method which tells you which condition to use? |