My problem is that I have a "editable" primary key of type varchar(9). I have added the key column to the form and the safeAttributes in the model. But when i call save() and see the query done in the database i see something like following:
UPDATE `tbproject` SET `ID`='mynewkey', ... other columns... WHERE `tbproject`.`ID`='mynewkey'
where ‘mynewkey’ is the value entered on the form. The problem is that due to the form post I overwrite the “old” value of my key which is in the database.
And therefore it doesn’t update anything cause the wrong key is used in the where part.
the correct sql would be
UPDATE `tbproject` SET `ID`='mynewkey', ... other columns... WHERE `tbproject`.`ID`='myoldkey'
Does someone know how to solve this or show me the right way to change the primary key value of a database entry?
Wow, reading all this, it seems to be a good idea to use auto incremented integers as id.
I was just about to modify the CRUD templates, because I realized I wasn’t able to insert new objects that used a varchar as id. Now that I see that there are so much other related problems, I think I will modify my db schema.