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

Hello,

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.
Reply
#2

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

https://codeigniter.com/user_guide/model...your-model

Code:
protected $primaryKey = 'other_id_field';
Reply
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB