Editor 1.2.4 change Name of Primary Key

Editor 1.2.4 change Name of Primary Key

MbdesignMbdesign Posts: 17Questions: 0Answers: 0
edited January 2014 in Editor
Hi,

I got a problem with my tables and the Primary key name id.

I want use my own Primary key field called customers_id instead of id

in Old Editor i do that and it works but not in 1.2.4 anymore.

$editor = new DTEditor(
$db, // DB resource
'customers', // DB table
'customers_id', // Primary key
'row_', // ID prefix to add to the TR rows (makes it valid and unique)
array( // Fields
new DTField( array(.......


Where i can change it?




that do not work in 1.2.4

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'customers', 'customers_id' )
->fields(........

thnak you


Markus

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    What you are using, the third parameter of `Editor::inst` should work - that will set the primary key: https://editor.datatables.net/docs/current/php/class-DataTables.Editor.html .

    There is also a `pkey()` function for this Editor class you could try:

    [code]
    Editor::inst( $db, 'customers' )
    ->pkey( 'customers_id' )
    ...
    [/code]

    Allan
  • MbdesignMbdesign Posts: 17Questions: 0Answers: 0
    Hello Allan,

    again the same issue when i use that

    Editor::inst( $db, 'customers', 'customers_id' )
    OR

    Editor::inst( $db, 'customers' )
    ->pkey( 'customers_id' )

    {"id":-1,"error":"","fieldErrors":[],"data":[],"aaData":[{"DT_RowId":"row_1","customers_id":"1","bpn_id":"900100","entry_company":"test GmbH & Co. KG","entry_gender":"m","entry_firstname":"Markus"....


    php works but json send again the id field.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    In the data you show above, it looks like it is working:

    [code]
    "DT_RowId":"row_1",
    "customers_id":"1"
    [/code]

    The primary key is used in the `DT_RowId` property with `row_` prefixed to make it valid for use in the DOM. The number used is that of the `customers_id` which you has specified as the primary key.

    Is that not what you were expecting?

    Thanks,
    Allan
This discussion has been closed.