Custom primary key not working for edit and delete
Custom primary key not working for edit and delete
Loren Maxwell
Posts: 406Questions: 99Answers: 10
in Editor
I'm using a custom primary key and my understanding is that the only change needed is to include the custom primary key field as the third parameter when initializing an instance of Editor on the server side:
// Editor instance
Editor::inst( $db, 'wiki_wikiforum_category', 'wfc_category' )
I can add record (which notably doesn't need a primary key), but I get this same error for edit and delete:
An SQL error occurred: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause'
Have I overlooked something?
This discussion has been closed.
Answers
Would be good to see your where clause. The "id" field is being used there which doesn't exist and should be called 'wfc_category' because that is what you call your primary key.
I agree.
I didn't have time to look through the Editor code to fish out the sql before I had to leave, but I did have enough to ask if I at least had everything configured properly.
I can do more digging this evening but just curious as to if I've completely missed something.
I've used DataTables quite a bit in this past year, but this is the first time with a table I didn't design (hence, no "id" field).
As long as
wfc_category
is unique and auto incrementing, then that should be all that is needed. We'd need to see the rest of your code to understand why anid
might be getting used.Allan
OK, I've found the offending piece of code.
I do logging according to my post "Robust audit logging": https://datatables.net/forums/discussion/46968/robust-audit-logging
Here was my code to retrieve the previous values:
So that's where the 'id' is introduced and the error pops up.
I've changed the code to require the primary key and use it:
And now when I call the function I pass the primary key using the Editor (see 'preEdit' and 'preDelete'):