Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82018

Create Row With Custom Primary Key

$
0
0

Greetings
I use custom primary key, named key_id instead of the id column.
I use custom function to create this unique key_id, and using setFormatter on the field for that, while in the javascript side, I sent the key_id as a hidden field with value of null or false, just to make sure it will use the setFormatter function.
Example:

$e = Editor::inst($db, 'customers', 'key_id')
                ->fields([
                    Field::inst('customers.key_id')->setFormatter(function ($data) {                        
                       if($data){
                          //Not Modifying the KeyId in case of editting.
                          return $data;
                         }else{
                           //Generating New Id for Newly created Row, which has $data of false or null;
                           return SomeSpecialFunctionForRandomKeyId();
                        }
                    }),
                    Field::inst('customers.name'),

It is creating it fine, but the problem is, when I listen for the json of the creating request in javascript, I get empty data array. (I'm expecting to get the newly created row in the data array).
When I truned on debug mode for sql queries, I got two of them:
1- One for insertion, which is doing well.
2- Second one for selecting the created row, which bind the value of (ID OF CREATED ROW) to the key_id primary key column. That's why I get empty array I guess.
Any mistakes in my script or any suggestions ?


Viewing all articles
Browse latest Browse all 82018

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>