Is there a way to manually set the ID of a new bean using RedBean PHP? I'm storing cached data from an API which generates the ID of each row and would just like to use that ID for simplicity.
I've read other threads that say to simply create a new column (row_id) or something, but I'd like to just use the unique generated ID as the ID.
1 Answer 1
As per MySQL doc
No value was specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. You can also explicitly assign 0 to the column to generate sequence numbers. If the column is declared NOT NULL, it is also possible to assign NULL to the column to generate sequence numbers. When you insert any other value into an AUTO_INCREMENT column, the column is set to that value and the sequence is reset so that the next automatically generated value follows sequentially from the largest column value.
If that's true, in RedBean you can do something like
$post = R::dispense('post');
$post->id = 234;
R::store($post);
I haven't tested this since i keep auto-incremented column set to integer default to 0 which automatically increments.