This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I'm trying to extend the RainLab.user, which uses auto increment id
as primary key. I want to use uuid
as model primary key for my distributive sites, at the same time will leave id
as primary key in MySQL InnoDB for efficience, so I added a new column uuid
in my plugin's migration. Besides, I updated the relative url /:id
in YAMLs to /:uuid
and following codes in plugin registration:
use RainLab\User\Models\User;
class Plugin extends PluginBase {
[...]
public function register() {
User::extend(function($model) {
/**
* The primary key for the model.
*
* @var string
*/
$model->primaryKey = 'uuid';
});
}
However, when I need to use the user model, for example the preview form /user/preview/XXXX-XXXX-XXXX-XXXX...
in backend, it told me that the record id XXXX-XXXX-XXXX-XXXX... not found in fatalError. Numeric id
for url /user/preview/id
is still working fine.
Does someone have any suggestion?
Last updated
Since no one has answered I will try to give you some thoughts, however I haven't tested any of it ...
I would check the following things:
- were migrations executed? check db that updated fields are present and uuids are filling in automatically ( this is my example from laravel based project it should be similar
$table->uuid('uuid')->unique()->default(myCustomGenerateUuidFunction());
- if you use uuid as PK then you should set $incrementing = false as well
- clean cache just in case :)
- check where fatal error happens - go and check it out in code ...
However if you wish to leave ID the easiest way to go would be to just add uniquely indexed field UUID so all native functions will stay as they are. Just check that routes /user/preview/id are blocked.
1-2 of 2