Hi,
I have a table that contains 2 columns:
+-------------+-----------+
| category | level |
+-------------+-----------+
| Cat | 1 |
| Cat A | 2 |
| Cat B | 1 |
| .... | ... |
+-------------+-----------+
on Client Side I create a simple editor:
editor = new $.fn.dataTable.Editor({
ajax: url + "json",
table: "#detail",
fields: [
{
label: "Category",
name: "category",
type: "display"
},
{
label: "level",
name: "level"
},
]
});
on Server Side (PHP):
$DB = $this->editorlib->getDatabase();
$ed = new Editor($DB, "category_table","category");
$ed->debug(true);
$ed->fields(
Field::inst('category')->set(false),
Field::inst('level')
);
$ed->process($_POST);
$ed->json();
When I tried to update Cat A level value to another value (3), the row is not updated but a new row with category value '0', and level value 3 inserted instead.
+-------------+-----------+
| category | level |
+-------------+-----------+
| Cat | 1 |
| Cat A | 2 |
| Cat B | 1 |
| 0 | 3 |
+-------------+-----------+
Debug log:
{
"data":[
{
"DT_RowId":"row_0",
"category":"0",
"level":3
}
],
"debug":[
{
"query":"SELECT category as \"category\" FROM category_table WHERE category = :where_0 ",
"bindings":[
{
"name":":where_0",
"value":"0",
"type":null
}
]
},
{
"query":"UPDATE category_table SET level = :level WHERE category = :where_0 ",
"bindings":[
{
"name":":level",
"value":"3",
"type":null
},
{
"name":":where_0",
"value":"0",
"type":null
}
]
},
{
"query":"SELECT category as \"category\", level as \"level\" FROM category_table WHERE category = :where_0 ",
"bindings":[
{
"name":":where_0",
"value":"0",
"type":null
}
]
}
]
}
From the log above we can see that the binding for ':where_0' is incorrect. It should be "Cat A".
However if I edit the 'Cat' Category, it works fine.
If it's possible, I would like to avoid changing the database structure and add a new primary key.
Thank you.
Danny.