Welcome Guest, Not a member yet? Register   Sign In
Using Update() on primary key named differently than id


when I am using the below code it will only work if my primary key field in the databaseĀ is named "id".
PHP Code:
$model->update($idVar, ['description' => $this->request->getPost('description')]); 

But because I will have to run many SQL Joins between tables I would like to be able to name my primary key fields differently.

How can I achieve this?

Thanks in advance for your help.

Have you tried using the documentation's suggestion of setting the primaryKey variable?


protected $primaryKey = 'other_id_field';

Thank you Craig. I was looking deeply into the documentation but must have missed this one.
It's excactly what I needed!

Theme © iAndrew 2016 - Forum software by © MyBB