Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redbean returning boolean columns as string #944

Open
noorbakerally opened this issue Jun 30, 2024 · 1 comment
Open

Redbean returning boolean columns as string #944

noorbakerally opened this issue Jun 30, 2024 · 1 comment

Comments

@noorbakerally
Copy link

I am having a problem using Redbean. I have a table photos having the photos definition:

+----------------+-------------+------+-----+---------+----------------+
| Field          | Type        | Null | Key | Default | Extra          |
+----------------+-------------+------+-----+---------+----------------+
| id             | int(11)     | NO   | PRI | NULL    | auto_increment |
| account_number | varchar(20) | NO   |     | NULL    |                |
| photo          | text        | YES  |     | NULL    |                |
| isDefault      | tinyint(1)  | YES  |     | 0       |                |
+----------------+-------------+------+-----+---------+----------------+

I have a small PHP script:

<?php
        require 'rbconnect.php';
        $photos = R::findOne('photos');
        var_dump($photos);
        $photos->id = intval($photos->id);
        $photos->isDefault = intval($photos->isDefault);
        echo json_encode($photos);
?>

First part of returned result var_dump($photos):

object(RedBeanPHP\OODBBean)#17 (11) {
  ["properties":protected]=>
  array(4) {
    ["id"]=>
    string(1) "1"
    ["account_number"]=>
    string(10) "1234567890"
    ["photo"]=>
    string(17) "sample_photo_data"
    ["isDefault"]=>
    string(1) "0"
  }
  ["__info":protected]=>
  array(8) {
    ["type"]=>
    string(6) "photos"
    ["sys.id"]=>
    string(2) "id"
    ["sys.orig"]=>
    array(4) {
      ["id"]=>
      string(1) "1"
      ["account_number"]=>
      string(10) "1234567890"
      ["photo"]=>
      string(17) "sample_photo_data"
      ["isDefault"]=>
      string(1) "0"
    }
    ["tainted"]=>
    bool(false)
    ["changed"]=>
    bool(false)
    ["changelist"]=>
    array(0) {
    }
    ["model"]=>
    NULL
    ["data.bundle"]=>
    array(0) {
    }
  }
  ["beanHelper":protected]=>
  object(RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper)#13 (0) {
  }
  ["fetchType":protected]=>
  NULL
  ["withSql":protected]=>
  string(0) ""
  ["withParams":protected]=>
  array(0) {
  }
  ["aliasName":protected]=>
  NULL
  ["via":protected]=>
  NULL
  ["noLoad":protected]=>
  bool(false)
  ["all":protected]=>
  bool(false)
  ["castProperty":protected]=>
  NULL
}

Second part of the returned json is:
{"id":1,"account_number":"1234567890","photo":"sample_photo_data","isDefault":"0","is_default":0}

I am having two ambiguities:

  1. If I do not do a casting both id and isDefault returned type is String, are not they supposed to be of type int?
  2. Casting is working for id but not for isDefault. When casting isDefault, it is instead recreating another column is_default.

Noor

@gabordemooij
Copy link
Owner

Sorry for the late reply. Have you tried:

R::getDatabaseAdapter()->getDatabase()->stringifyFetches( FALSE );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants