Skip to content

Issue with models sans auto-incrementing primary key #9

Description

@notacouch

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 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions