Hello all!
I'm new in forums, so I'm sorry, if my topic is somehow incorrect. Also sorry for my worse english.
Few days ago, I tried to search my problem in forums, in google, in bug tracker, but didn't find any solution.
[Attaching my DB scheme with N:N relation.]
My source code (N:N):
$crud->set_relation_n_n("categories", "categories_servers", "categories", "id_server", "id_category", "title", "id_category");
Symptomps:
- Creating/updating record (server item)
- Result is, that in N:N table apears new records and id_server is correct
- Problem is, that id_category row is always incorrect - not PK from table categories, but index from 0 to X (X = count of selected items in add/edit form)
I tried to debug grocery crud model and found working solution for my case. But I don't know if it's correct and won't break anything other.
My solution:
Replace variable $counter with $primary_key_value on line 406:
$where_array[$field_info->priority_field_relation_table] = $primary_key_value;
and line 412:
$this->db->update( $field_info->relation_table, array($field_info->priority_field_relation_table => $primary_key_value) , $where_array);
Hope, it will be helpful.