Welcome Guest, Not a member yet? Register   Sign In
Multiple ignore-fields for is_unique-function
#5

I was able to fix the issue. I made custom function for the validation to check 2 database fields:

   
Code:
    public function is_unique_multiple(string $str = null, string $field, array $data): bool
    {
        // Grab any data for exclusion of a single row.
        list($field, $ignoreField, $ignoreValue, $ignoreField2, $ignoreValue2) = array_pad(explode(',', $field), 5, null);

        // Break the table and field apart
        sscanf($field, '%[^.].%[^.]', $table, $field);

        $db = Database::connect($data['DBGroup'] ?? null);

        $row = $db->table($table)
                  ->select('1')
                  ->where($field, $str)
                  ->limit(1);

        if (! empty($ignoreField) && ! empty($ignoreValue))
        {
            $row = $row->where("{$ignoreField} !=", $ignoreValue);
        }
        
        if (! empty($ignoreField2) && ! empty($ignoreValue2))
        {
            $row = $row->where("{$ignoreField2} =", $ignoreValue2);
        }

        return (bool) ($row->get()
                        ->getRow() === null);
    }
  
This ensures that entries with other podcastsIDs will not interfere with the validation Smile
Reply


Messages In This Thread
RE: Multiple ignore-fields for is_unique-function - by mboehmlaender - 10-29-2020, 03:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB