Hi Amit Shah,
Thk for your help.
I have tried it before but my problem is not when data inserted , my data inseerted correctly, my problem is when I have review this data or edit data. because I used the set_relation_n_n when any modificaction for my situation.
My real situation now is not example.
tb_sites
id
name
url
image
......
......
fk_category
fk_type
fk_language
fk_owner
tb_add_text
id
text
fk_site
My insertion is true but my link from the list to edit selected element is not correct, this is the error return.
I know this relationship is not correct but I not know other form to represent.
Error Number: 1066
Not unique table/alias: 'add_texts_site'
SELECT *, text as s1cb251ec FROM (`add_texts_site`) JOIN `add_texts_site` ON `add_texts_site`.`fk_site` = `add_texts_site`.`id` WHERE `fk_site` = '130' ORDER BY `add_texts_site`.`text`
Filename: C:\xampp\htdocs\admin\system\database\DB_driver.php
Line Number: 330
This is my bad relation
$crud->set_relation_n_n('add_text', 'add_texts_site', 'add_texts_site', 'fk_site', 'fk_site', 'text');
This is my controller
try {
$crud = new grocery_CRUD();
$crud->set_theme('flexigrid');
$crud->set_table('sites');
$crud->set_subject('Directorio de Sitios');
$crud->set_language('spanish');
$crud->unset_export();
$crud->set_field_upload('image', 'assets/uploads/files');
$crud->columns('name', 'url', 'description', 'fk_type', 'fk_owner', 'active');
$crud->set_relation('fk_category', 'categories_site', 'category');
$crud->set_relation('fk_type', 'types_site', 'type');
$crud->set_relation('fk_language', 'languages', 'language');
$crud->set_relation('fk_owner', 'owners_site', 'name');
$crud->set_relation_n_n('tags', 'sites_tags', 'tags_site', 'fk_site', 'fk_tag', 'tag');
$crud->set_relation_n_n('parent', 'parents_site', 'sites', 'parent_site', 'child_site', 'name');
/**
* Relaciones n-1 donde la FK no esta en
* la tabla que estamos haciendo render
*/
$crud->display_as('name', 'Nombre')
->display_as('url', 'URL')
->display_as('description', 'Descripción')
->display_as('fk_type', 'Tipo')
->display_as('fk_owner', 'Propietario')
->display_as('image', 'Imagen')
->display_as('active', 'Estado')
->display_as('priority', 'Prioridad')
->display_as('fk_category', 'CategorÃa')
->display_as('fk_language', 'Idioma')
->display_as('parent', 'Sitios Padre')
->display_as('tags', 'Palabras Claves')
->display_as('add_text', 'Texto Adicional')
//This is my prblem
$crud->set_relation_n_n('add_text', 'add_texts_site', 'add_texts_site', 'fk_site', 'fk_site', 'text');
$crud->callback_add_field('add_text', array($this, 'edit_field_add_text_callback'));
/**
* Insertando campos en las tablas "icons_site" y "add_text"
*/
$crud->callback_after_insert(array($this, 'after_insert'));
$crud->unset_back_to_list();
$output = $crud->render();
$this->load->view('sites/edit_sites_view', $output);
} catch (Exception $e) {
/* Si algo sale mal mostramos error */
show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
}
Callback after insert
function after_insert($post_array, $primary_key) {
//Inserta el texto adicional en la tabla "add_text"
$insert = array("text" => $post_array['add_text'],
"fk_site" => $primary_key
);
$this->db->insert('add_texts_site', $insert);
}
Callback add field
function edit_field_add_text_callback($value, $primary_key) {
return '<textarea rows="1" cols="30" name="add_text"></textarea>';
}
Please excuse my bad English :)