One of my models is just keeping track of data in a third party service. The id field is set to theirs. Saving the model resets that id field to 0 because the insert_id is forced on it here:
|
$this->setAttribute($this->idField, ee()->db->insert_id()); |
Instead of editing that I had just copied the method and removed that bit of code for that particular model, but while documenting it hit me a condition could be used there instead, save the insert_id if it is not zero.
E.g. instead of:
$this->setAttribute($this->idField, ee()->db->insert_id());
Perhaps change to (untested):
$this->setAttribute($this->idField, ee()->db->insert_id() ? : $this->getAttribute($this->idField)); // double-checked, shorthand ternary is okay since Channel-Data requires PHP 5.3+ anyways
One of my models is just keeping track of data in a third party service. The id field is set to theirs. Saving the model resets that id field to 0 because the
insert_idis forced on it here:Channel-Data/channel_data/libraries/Channeldata/base/BaseModel.php
Line 240 in c8ce9d9
Instead of editing that I had just copied the method and removed that bit of code for that particular model, but while documenting it hit me a condition could be used there instead, save the insert_id if it is not zero.
E.g. instead of:
Perhaps change to (untested):