Editor Compound Key PHP postCreate Event $row value is null
Editor Compound Key PHP postCreate Event $row value is null
paul@dmcreative.com
Posts: 27Questions: 5Answers: 0
in Editor
PHP library using Editor 1.9.0 when using a table with a compound key such as
$editor = Editor::inst( $db, 'visitors', array('visitor_id', 'visit_date') );
the Post create function variable $row is returning a value of Null
->on( 'postCreate', function ( $editor, $id, $values, $row )
Is this an error or expected behavior?
This discussion has been closed.
Replies
I have found out why this is happening and it seems to be a flaw in how the primary key, "row ID' - _pkey is generated when the setValue() method is used to compute a value for on or more of the elements of a primary key.
If a field that makes up a key is not submitted by the js code an error is returned. Once all fields that make up a key are submitted the php code accepts the ajax submission as valid. I have observed that the primary key returned as the id of the values and the hash key separator is comprised of the values from the submitted values. If a value is changed using the setValue() method the correct data is inserted into the database, but the primary key ID returned does not reflect the values that have been set and reverts to the values from the form submission.
This seems to be contrary to the instructions per the the getting started page
https://editor.datatables.net/manual/php/getting-started
No special configuration is required on the client-side to support compound keys, however, when creating new rows you must submit the data for the columns that make up the compound key (an error will be shown otherwise). Editor cannot currently read information that is generated by the database. If you need to set a server-side computed value (e.g. current time), use the Field->setValue() method to set the value. This limitation is due to the database engines that Editor currently supports.
Thank you for letting me know about this. I'm about to start work on a series of patches for 1.9.1 and I'll include this in that to have it fixed for the next release.
Regards,
Allan
I've been digging into this and its very similar to the issue here. I believe the idea I propose there would fix this as well, and I've just tried prototyping it, but its a significant change which is going to touch a number of areas of the code.
I'm afraid this change won't make it in for 1.9.1, but the issue is open and I've got a plan to address it, but for the moment, the way to do this would need to be to have the client-side submit the parameters, or manipulate the submitted data before it is given to Editor (this is probably the way I'd do it myself at the moment).
Allan
allan,
I have written for myself a rather simple solution for this issue, that has been working well. As the issue only revolves around create I isolated the data creation for the key from the key generated from the passed key data and wrote a simple function to generate the key to replace the passed key. I have been able to use the same methodology on MySQL, MicrosoftSQL, and also Oracle SQLanywhere.
If you would like to see what I did, please feel free to email me. As untested code I do not wish to post it here where someone could use it not knowing the ramifications.
Paul