Welcome Guest, Not a member yet? Register   Sign In
Set symbol in rule is_unique

(This post was last modified: 04-25-2020, 09:30 AM by 5flex.)

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 != (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 (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.namesub_id=, {id}] 


PHP Code:
is_unique[categories.namesub_id,'=', {id}] 


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?

Theme © iAndrew 2016 - Forum software by © MyBB