gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

how to set custom id value instead of auto increment #657

Closed sadick254 closed 6 years ago

sadick254 commented 6 years ago

Is it possible to set a value on the id instead of auto-increment done by the databases.

$book = R::dispense('book');
$book ->id = 'some value';

R::store($book);

When I do it like above, there is nothing getting persisted on the db.

gabordemooij commented 6 years ago

Hi there,

Managing your own primary keys like that does not work with RedBeanPHP. If you want custom ids you need to implement your own QueryWriter. Copy-pastable examples are available:

https://redbeanphp.com/index.php?p=/uuids

That page describes how to use MySQL/PostgreSQL UUIDs with RedBeanPHP. Hope this helps!

Cheers Gabor