Data not being returned by Editor on create

Data not being returned by Editor on create

alphadadalphadad Posts: 12Questions: 6Answers: 0

Hiya ...

I've been struggling with this for a little while and could use some insight.

I have a table with 2 unique fields ... id (auto incrementing) ... and uuid (a uuid generated by a MySQL trigger before insert). I'd prefer to use uuid as my pkey with DataTables and Editor so that I don't have a simple integer for my row_ids ... so I instantiate Editor with ...

Editor::inst( $db, 'myTable', 'uuid' ) ...

... then add all the fields. All works fine with loading, editing and updating ... but ... when I "create" with Editor, it doesn't return data so that the table is updated. JS Console logs indicate that the data object is "undefined". I check the db and the record has been successfully inserted but the data has not been returned so that the DataTable can be updated. To test, I changed my Editor instantiation to ...

Editor::inst( $db, 'myTable', 'id' )

... and all works fine ... loading, editing, updating and creating all work smoothly and the DataTable is updated faithfully on each operation.

Any suggestions so that I can get the same functionality using my uuid field as the pkey?

Dave

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin
    Answer ✓

    Hi Dave,

    The issue is that when you create a new row Editor will get the last insert id using the PDO lastInsertId method - which in this case will be returning your pkey (if I am correct, if you take a look at the JSON return from a create action you should see something like DT_RowId: "row_{int}" rather than a uuid).

    Are you able to change your table schema to treat the uuid column as the primary key? That would then allow it to work.

    Beyond that, I'm not actually sure there is a way to do it built in to the libraries (I an't think of one anyway!). You'd probably need to post-process the data that would be returned, replacing the pkey with the uuid.

    Sounds like a future enhancement option!

    Allan

This discussion has been closed.