Propel2
Propel2 copied to clipboard
Saving object with modified primary key
I've tried searching for a similar issue but couldn't find any (here at least, I did find something similar but with no clear solution on the forums). How can I save an object if the PK has been modified ? The log shows that new PK is used in the WHERE clause (e.g: Original PK was 25)
[2015-08-09 07:20:43] defaultLogger.INFO: UPDATE
author
SETID
=55 WHERE author.ID=55 [] []
Sandbox: http://sandbox.propelorm.org/486a545
The only solutions I could think of were:
- Deleting the old object and saving a new one with the new PK
- Use a SQL query instead of set... and save()
Thanks :wink:
I think this issue explain another weird behavior with cross-ref and primary keys that cannot be updated once the record has been created.
I think a possible (and the easiest) solution would be to store the Pk when the object is created in another variable called originalPK or something.
Is someone able to make a PR here with suggested changes?
Is anyone on this behaviour? Otherwise, I would try.
Meanwhile: A workaround could be copying the object.
Go for it
I created a pull request for that. https://github.com/propelorm/Propel2/pull/1896
The checks are failing because of:
Error: dealerdirect/phpcodesniffer-composer-installer contains a Composer plugin which is blocked by your allow-plugins config. You may add it to the list if you consider it safe.
You can run "composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer [true|false]" to enable it (true) or disable it explicitly and suppress this exception (false)
See https://getcomposer.org/allow-plugins