Hello again toopay, I found a weird situation where some code like the following caused two records to be inserted instead of one:
$this->model = new Model\User()
$this->model->username = 'MyUser';
$this->model->save();
$this->model = $this->model->last_created();
I can remove this issue by changing the last line to:
$this->model->id = $this->db->insert_id();
Looking at your code from line 2479 of core.php I can’t see why this would be happening!? Is there an issue with the $this->model=$this->model->last_created() above? I’ve managed a slightly messy workaround but just wondering if I’m doing something silly.
This situation has come about because I’m trying to abstract all my repetitive CRUD tasks into a controller… there are callbacks in the child controller which can customise the data being saved, inserted etc and the behaviour after saving.
EDIT: Although it turns out $this->db->insert_id() is returning 0 even though a record was inserted!?