Custom Keys
From RedBean
Custom Primary Keys
If you just want to change primary key IDs consider this chapter: Prefixes
By default all primary keys will be called 'id'. This might not be what you want if you use an existing database. RedBean offers a very convenient way to allow maximum flexibility.
The only thing you have to do is override the getIDField() method; like this:
class MyWriter extends RedBean_QueryWriter_MySQL {
public function getIDField( $type ) {
return $type . "_id";
}
}
In this example the primary key will be constructed using the table name. In case we have a bean called 'person' the new primary key name will be 'person_id'. Note that because the type is send to the function you can make exceptions for certain tables if you like. So, even if you want to customize primary keys you still don't need to write a single line of configuration; using basic OOP techniques we still manage to allow maximum flexibility.
Now replace the existing Writer in the toolbox with yours and you are done:
$writer2 = new MyWriter($adapter);
$redbean2 = new RedBean_OODB($writer2);
$movie = $redbean2->dispense("movie"); //uses movie_id as primary key
Also see: Prefixes

