Say you have a database table that has a different primary key than the standard id.
Let's say it's named customer_number
To make sure everything works as usual for this you have 3 locations to keep in mind for the primary key to function properly:
The model The config_form.yaml The config_list.yaml
In the model you need to add the variable $primaryKey
/**
* Customer Model
*/
class Customer extends Model {
/**
* @var string The database table used by the model.
*/
public $table = 'customers';
public $primaryKey = 'customer_number';// Note the uppercase K
.........
In config_list.yaml you have the variable recordUrl: that needs changing. Default this has :id appended behind it. You need to change :id to your primary key name
recordUrl: author_name/client/customeredit/update/:customer_number
in config_form.yaml you have the variable redirect: under create: There too you need to change out :id for your primary key name
redirect: author_name/client/customeredit/update/:customer_number
And now you should be good to go with your different primary key.
Last updated