0

if I would not want to give continues id's to something the user can create (since then he can see how many have been created before), is it possible to change cakes strategy of creating those keys?

I just don't want the user to know how 'successful' or not a project is.

Gundon
  • 2,081
  • 6
  • 28
  • 46
  • You could use UUIds. Cake supports those natively. Those are kind of random 36 char strings which cloak the count quite effectivly. – mark Apr 22 '13 at 08:52
  • See also [uuid v4 generation](http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid/15875555#15875555). – Ja͢ck Apr 22 '13 at 08:58

1 Answers1

1

UUIDs are a possible way that is natively supported by cake: http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html#model-and-database-conventions

A primary key char36 field will automatically use those UUIDs.

Pros:

  • uniqueness across the whole application
  • cloak the count quite effectively (your main objective)

Cons:

  • order is not necessarily correct anymore (relies on created then?), especially with batch imports and multiple created dates.
  • need more space and make your queries slower.

Example:

5168a56a-f708-41b3-81ee-2f7152b0caef
...

An alternative would be use slugs for your user created content and always refer to that only by their slug (never by id). This way the autoincremented primary key can still be used for internal lookup and joins etc, but the frontend never really sees the id, as the slug is the main lookup field. Don't forget to index this slug field, though, as string-lookups are faster than.

mark
  • 21,691
  • 3
  • 49
  • 71