gabordemooij / redbean

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

Long Int problem #939

Open sgdot opened 4 months ago

sgdot commented 4 months ago

Hi, to store telegram chat id, I need large integers, including those with negative values, but redbean can't do it

I have file

use RedBeanPHP\R;

require dirname(__DIR__) . '/vendor/autoload.php';

R::setup('mysql:host=localhost:3306;dbname=mydb', 'user', 'mp123');

$test1 = R::dispense('test1');
$test1->testSign =-1000000000000;
$id = R::store($test1);
var_dump($id);

$test2 = R::dispense('test2');
$test2->testSign_id =-1000000000000;
$id = R::store($test2);
var_dump($id);

$test1 save long int as double scheme

-- mydb.test1 definition

CREATE TABLE `test1` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `test_sign` double DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

$test2 failed when saving because test_sign_id has type int(11) unsigned scheme

-- mydb.test2 definition

CREATE TABLE `test2` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `test_sign_id` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `index_foreignkey_test2_test_sign` (`test_sign_id`)
) ENGINE=InnoDB 
gabordemooij commented 3 months ago

IDs have a restricted type. But you can use a bigint if you like. Just add it manually, RedBeanPHP will not change it.

$a = R::dispense('aaa');
R::store($a);
R::exec("ALTER TABLE aaa ADD COLUMN val bigint");
$a->val = -1000000000000;
R::store($a);
print_r(R::inspect('aaa'));
print_r(R::findAll('aaa'));