⚠ 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

set_relation not marked as required not working



jcasanova
  • profile picture
  • Member

Posted 21 June 2012 - 14:25 PM

I got a set_relation (dropdown) not marked as required (*) in my form, but when hit the SAVE button, the SQL trow an error because the field is in the QUERY. (the red ones)

SQL: INSERT INTO "trafo" ("descripciontrafo", "tag", "[color=#ff0000]id_alimentador[/color]", "idtrafonet", "direccion", "idregion", "idcomuna", "lat", "lng", "voltaje_nominal", "kva", "serie", "tap", "fabricante") VALUES ('Transf-IDVIRT67', 'TRFVIRTUAL', '1', [color=#ff0000]''[/color], 'calle 3, 4', '13', '13106', '-123456', '-132456', '100', '100', 'SVC1234', '3', 'Schaffner');


as it has not required it shouldn't be on the query

$crud->display_as("idtrafonet","Equipo Trafonet");
$crud->set_relation('idtrafonet','trafonet','serial');
$crud->required_fields('descripciontrafo','tag','id_alimentador','direccion','idregion','idcomuna','lat','lng','voltaje_nominal','kva','tap');

[attachment=206:form.jpg]

any idea?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 21 June 2012 - 22:48 PM

You can simply have a callback_before_insert and a callback_before_update like this:


$crud->callback_before_insert(array($this,'remove_id_alimentador'));
$crud->callback_before_update(array($this,'remove_id_alimentador'));


and


public function remove_id_alimentador($post_array)
{
unset($post_array['id_alimentador']);
return $post_array;
}


This is the normal way that grocery CRUD update and insert, unless you have the id_alimentador allowed from the database to be NULL. Then you will simply have the [color=#ff0000]''[/color] to [i][color=#ff0000]NULL[/color][/i]