0
votes

I save the IP as a numeric value in the database. When i fetch it I use a virtualField with and INET_NTOA SQL Expression.

I want the IP to be unique, therefore I use the isUnique Validation rule in the model. The Problem is that this rule validates the ip address against the numeric value in the DB.

Is there a way I can modify the value of the field only for this rule before validation? The other rule is "ip" which needs the IP as a address not a numeric value.

1

1 Answers

0
votes

I'd suggest you create a custom validation rule that checks if the converted IP is unique.

…
'rule' => 'ipIsUnique',
…

// customize as needed
public function ipIsUnique($data) {
    return $this->isUnique(array_map('ip2long', $data));
}