Is it possible to manually set the ID of newlines using RedBean PHP?

I am using RedBean PHP to upload some data from a webpage to a database, and I need to keep outdated identifiers, preferably as a primary key field. Is it possible to do this with RedBean?

When I try to set id like this:

$bean->id = 56;

No row inserted - the query created instead becomes "UPDATE WHERE id= 56", which does nothing because the record does not exist yet.

+3
source share
3 answers

. legacy_id , .

+4

, SQL exec:

    $id = 60000;
    $name = 'bob';

    R::exec('insert into person(id) values('.$id.')');
    $person = R::dispense('person');
    $person->id = $id;
    $person->name = $name;
    R::store($person);
+4

I started the redbean github project for this version, the first version supports the presence of custom id fields.

You should tell redbean that the id field name (if not " id")

R::getRedBean()->idFieldMap= array('adres'=>'id_adres','contact'=>'contact_id'); // settings for current database

Future enhancements: support for custom foreign keys.

https://github.com/freelanceniek/redbeanx

0
source

Source: https://habr.com/ru/post/1794354/


All Articles