CodeIgniter Forums

Full Version: Set symbol in rule is_unique
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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}] 

or

PHP Code:
is_unique[categories.namesub_id,'=', {id}] 
@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?