I have to use UUIDs as my primary key on some of my tables because I am using some unions and haven't found a a way to make unions work with auto increment.
I have experimented with different ways ofhaving a UUID as primary key and found that using an add callback is best (I don't whether it is but using the value on the hidden field type overrides it on edit. So I have
$crud->callback_add_field('rule_id',array($this,'rule_uuid_callback'));
and my callback is
function rule_uuid_callback() {
return'<input type="hidden" name="rule_id" value="'.$this->crud_model->uuid().'">';
}
$this->crud_model->uuid() selects a UUID from MySQL.
This might be a silly way of doing it but I have not found a way to do an auto UUID in MySQL.
When you save the record the prompt appears at the bottom of the screen with the following code
<p>
Your data has been successfully stored into the database.
<a href="http://127.0.0.1/~simonfrank/iresponse/index.php/application/rules/edit/0">Edit rule</a>
or
<a href="http://127.0.0.1/~simonfrank/iresponse/index.php/application/rules">Go back to list</a>
</p>
(notice the 0 after edit)
This on its own is not really a hassle as I can CSS hide the first link. Where it is much more difficult is if I am using set_relation_n_n when the record is saved as it does not know the primary key (even though it is in the the field and in the post array). I therefore end up a 0 key in my lookup table for rule_id.
I have considered using before insert callabcks to set the primary key but don't know how to do this having skimmed through the source code.I also considered having an after insert callback to redirect back to edit i.e. have a smaller add screen with no set_relation_n_n and then when saved redirect to an edit screen with all fields - clunky but it would work (I think).
Any suggestions, work arounds ? (if it is me I apologise in advance, but I have tried searching and varying experiments to try and address it.