# Using uuid for edit/delete in CRUD

**URL:** https://discourse.cakephp.org/t/using-uuid-for-edit-delete-in-crud/11303
**Category:** Need Help
**Created:** [June 21, 2023, 9:21pm UTC](https://discourse.cakephp.org/t/using-uuid-for-edit-delete-in-crud/11303 "2023-06-21T21:21:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![PeterVARGA](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/petervarga/32/1928_2.png) [@PeterVARGA](https://discourse.cakephp.org/u/PeterVARGA)
#### Post date: [June 21, 2023, 9:21pm UTC](https://discourse.cakephp.org/t/using-uuid-for-edit-delete-in-crud/11303/1 "2023-06-21T21:21:30Z")

</div>

CakePHP 4.4.14  
friendsofcake/crud: 6.2.0

For simply security reasons and also not to reveal the amount of rows in the table I want to use the `uuid` field for the `edit/delete` actions.

Usually it works like this `/edit/123`. This is exactly what I **don’t want to have**. Therefore I want to change it to `/edit/446a1a76-4eac-4b2d-8825-7e3a7e91f4a0`.

Yep, and now I get the error message that it cannot be converted to number; this is correct, because `uuid` is not a number.

I checked the events but there is - [also according to the CRUD documentation](https://crud.readthedocs.io/en/latest/actions/edit.html#crud-beforefind) - the `WHERE` already set.

> **query** A `Query` object from the `Repository` where `$PrimaryKey => $IdFromRequest` is already added to the conditions.

How can I set/change the field in the query to `uuid`. As I understand it, it must be done _before_ `beforeFind` because the type for the parameter is already set to `integer` and `uuid` is not an integer.

```auto
    $this->Crud->on('beforeFind', function(\Cake\Event\EventInterface $event) {
        $event->getSubject()->query->where(['uuid' => "uuid-as-string]);
    });

```

Doesn’t work because the condition is **added** and the `id` remains in the query.

To make it clear: Each table has the primary key `id` - according to the CakePHP rules - but each table has also the field `uuid` which is used for public access. Internally the project uses the `id`.

---

<div class="post-metadata">

### Author: ![PeterVARGA](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/petervarga/32/1928_2.png) [@PeterVARGA](https://discourse.cakephp.org/u/PeterVARGA)
#### Post date: [June 23, 2023, 2:47pm UTC](https://discourse.cakephp.org/t/using-uuid-for-edit-delete-in-crud/11303/2 "2023-06-23T14:47:23Z")

</div>

[Solution is here.](https://stackoverflow.com/a/76541192/3179492)
