master detail table update problem
master detail table update problem
alpaltunel
Posts: 14Questions: 3Answers: 0
Hello
I am working on a editor on an existing table.
MasterTable
ID, is_active, sort_order
Detail Table
MasterID, Name, Description, language
detail data:
1, 'name', 'description', 'english'
1, 'adi', 'aciklama', 'turkish'
problem:
when I update is_active field the detail records with two different language options are updated and overwritten.
1, 'adi', 'aciklama', 'turkish'
1, 'adi', 'aciklama', 'turkish'
and english data is updated with turkish data.
$edt->inst($_db, 'MasterTableName')
->fields($flds)
->where("DetailTableName.language", $_SESSION['lng']) //->which is 'turkish'
->leftJoin("DetailTableName", "DetailTableName.MasterID", '=', "MasterTableName.ID")
->process($_POST)
->json();
this does not works. my where condition is completely ignored.
how to seperate these two fields?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
The
Editor->where()
condition is not applied when updating data. It is assumed that the primary key value is unique to the row being edited. Does your table have a unique parameter key?Allan
Thanks for quick reply Allan.
Yes both tables has ID fields which are unique and auto_increment.
but I dont know how to handle them?
MasterTable
ID, is_active, sort_order
Detail Table
ID, MasterID, Name, Description, language
how can I fix the server script part?
Can you show me what
$flds
is and also your Javascript configuration for DataTables and Editor.Allan
I am trying to add the DetailTableName.ID field to editor at the moment :)
but it doesnt accept it as a seperate key and continues to update Name field.
also when I try to add new record the MasterID field on the detail table is set as '0'.
Is there any way to implement all these?
This is exactly what I was going to suggest as it happens :-). You need to add that as a hidden field in the Javascript Editor and also to the fields in the PHP. That should give the server-side enough information to be able to update the field correctly on the joined table.
Are you getting any errors if you add that?
For both of the child rows?
Allan
unfortunately it updates both fields again. where clause should be executed if it exists. I will change the php code if necessary. can you suggest another solution?
the only solution to this situation is to apply the where condition otherwise all records are updated.
in Editor.php file:
private function _insert_or_update ( $id )
at the end of the function:
should be added and where condition should be applied!
I really thought that would work. I'll construct an example here and try to replicate the issue. Will let you know how I get on with that.
Allan
Hi Allan
did you have any chance to check situation? if helps I can send you database schema and sample data.
I haven't yet I'm afraid. If you could send me the schema that would be really helpful. The full PHP that you are using and also Javascript might be useful as well. allan @ this-domain.net will get to me.
Allan