Skip to main content
Topic: 0 duclipate numeric (Read 1188 times) previous topic - next topic

0 duclipate numeric

hi!!!
I need in a numeric field of 8, that does not allow duplicates, but that also allows inserting 0 as a duplicate value. Can you help me? How should I do it? Thank you!!!

Re: 0 duclipate numeric

Reply #1
Hello DDiaz,
I am brand spanking new to PHPRad but not to app dev. PHPRad may have a better way to handle this but here is how I would handle that case.
Unique index is out since you need to duplicate zeros.
In the 'Before Insert' table event I would check the table for that value. if found notify the user and redirect or create a new value and check again.
If not found proceed with the insert.
Just my 2 cents hope it gives you some ideas.

Re: 0 duclipate numeric

Reply #2
Without removing the index, achieve this by modifying the controllers. But when specifying again it makes them original, I suppose I will have to make it custum. But I leave my temporary solution in case someone wants to improve it ...


Code: [Select]
SharedController.php

/**
     * persona_per_docnro_value_exist Model Action
     * @return array
     */
function persona_per_docnro_value_exist($val){
$db = $this->GetModel();
$exist=false;
if ($val > 0) {
$db->where('per_docnro', $val);
$exist = $db->has('persona');
}
return $exist;
}


PersonaController.php

//Check if Duplicate Record Already Exit In The Database
//if(isset($modeldata['per_docnro'])){
if (isset($modeldata['per_docnro']) and ($modeldata['per_docnro'] > 0 ) ){
$db->where('per_docnro',$modeldata['per_docnro'])->where('perid',$rec_id,'!=');
if($db->has($tablename)){
$this->view->page_error[] = $modeldata['per_docnro']." ¡Ya existe!";
}
}