At the moment, we have hard-coded code in the Validation file, for the is_unique function:
PHP Code:
if (! empty($ignoreField) && ! empty($ignoreValue))
{
$row = $row->where("{$ignoreField} != ", $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}]