⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

throws an error if unique field is empty on edit



Tomexsans
  • profile picture
  • Member

Posted 08 May 2014 - 08:19 AM

I found this error i don't know if it is a bug or something, But if you try to add a column in unique_fields() and if you edit it, it will throw an error if that field is empty. Saying that 

 

"The field name doesn't exist in the database. ".
"Please use the unique fields only for fields ".
"that exist in the database"

 

Question why is this line https://github.com/scoumbourdis/grocery-crud/blob/master/application/libraries/Grocery_CRUD.php#L805

Checking for the unique_fields() value rather than checking the availability of that column? what if i have unique fields that are default no data? i have been surfing for a day now and can't seem to find any answers, so i created mine , if anyone have a better answer let me know.

 

On line 805/ libraries/grocery_CRUD.php

$database_columns = array_keys((array)$row);
if(!in_array($field_name,$database_columns))
{
    throw new Exception("The field name doesn't exist in the database. ".
                         "Please use the unique fields only for fields ".
                        "that exist in the database");
}

$previous_field_name_value = $row->$field_name;

if($previous_field_name_value != $field_name_value)
{
    $form_validation->set_rules( $field_name,
                                 $field_types[$field_name]->display_as,
                                 'is_unique['.$this->basic_db_table.'.'.$field_name.']');
    $form_validation_check = true;
}

Amit Shah
  • profile picture
  • Member

Posted 08 May 2014 - 17:56 PM

well 1 question why u trying to set the table name along with the field name cuz wht it is going to do is automatically set it agains the table.. so i will recommend u doing it simply by setting the field name.. not table.fieldname


Tomexsans
  • profile picture
  • Member

Posted 11 May 2014 - 09:12 AM

Funny you said that, but i did not put any table on my field, how did you come up with that? the main problem here is that it returns an error if the unique field is empty on the first place.  My table is populated before i use GC and when i tried to add a certain a column in unique_fields it throws an error if i edit that row. and that column has no data in it.

 

As you can see i included a link that checks not the column exists but if the value of that column exist.


Amit Shah
  • profile picture
  • Member

Posted 12 May 2014 - 13:09 PM

$form_validation->set_rules( $field_name,
                                 $field_types[$field_name]->display_as,
                                 'is_unique['.$this->basic_db_table.'.'.$field_name.']');

This code of your above - check yourself - what you believe it is going to try and check.. just the field name or <table>.<field> name?


Tomexsans
  • profile picture
  • Member

Posted 13 May 2014 - 08:14 AM

You do not understand my point, that code is doing great on what it does, im stressing out that on line 805 why does it have to check if the column is empty. what if i have a unique column and the default is NULL. Nevermind.


jinbatsu
  • profile picture
  • Member

Posted 12 August 2018 - 21:00 PM

You do not understand my point, that code is doing great on what it does, im stressing out that on line 805 why does it have to check if the column is empty. what if i have a unique column and the default is NULL. Nevermind.

 

Thank You for this fix, it is 4 year old post I know, but this work if we have default NULL on unique field as you said, thanks!