gabordemooij / redbean

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

redbean does not reference bean properties correctly #515

Closed nekromoff closed 8 years ago

nekromoff commented 8 years ago

$limit=R::findOne('limits', 'userid=?', [$userid]);

log: SELECT limits.* FROM limits WHERE userid=1 LIMIT 1 -- keep-cache resultset: 1 rows

after: echo $limit I get: {"id":"1","userId":"1","userLimit":"100"}

however after trying: echo $limit->userLimit nothing is printed out. Similarly after trying: echo $limit->user_limit or echo $limit->userlimit nothing is printed out either.

gabordemooij commented 8 years ago

Have you tried: user_id and $limit->user ?

nekromoff commented 8 years ago

Hello,

no I haven't, but why woudl suddenly userlimit in $limit would be changed to something like user only? This goes against all the docs.

nekromoff commented 8 years ago

Ok, I've tried both to no avail, i.e. echo prints nothing.

nekromoff commented 8 years ago

print_r of $limit, if that helps: RedBeanPHP\OODBBean Object ( [properties:protected] => Array ( [id] => 1 [userId] => 1 [userLimit] => 100 )

[__info:protected] => Array
    (
        [type] => limits
        [sys.id] => id
        [sys.orig] => Array
            (
                [id] => 1
                [userId] => 1
                [userLimit] => 100
            )

        [tainted] => 
        [changed] => 
    )

[beanHelper:protected] => RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper Object
    (
    )

[fetchType:protected] => 
[withSql:protected] => 
[withParams:protected] => Array
    (
    )

[aliasName:protected] => 
[via:protected] => 
[noLoad:protected] => 
[all:protected] => 

)`

nekromoff commented 8 years ago

after changing database column name to lowercase userlimit, it works.

definitely a bug in Redbeanphp

gabordemooij commented 8 years ago

Sorry for my previous response, I was too tired I think. I was a bit confused.

I have tried to reproduce the issue, the following code snippet seems to work fine:

Did I miss something ?

$l = R::dispense('limit');
$l->userLimit = 999;
$id = R::store($l);
$x = R::load('limit',$id);
var_dump($x->userLimit);

prints:

string(3) "999"

I would love to fix a bug - however to do so - I must be able to reproduce it properly.

cheers, Gabor

nekromoff commented 8 years ago

My code is as shown in the first comment: $limit=R::findOne('limits', 'userid=?', [$userid]);

table: `Column Type

id int(11) Auto Increment

userId int(11)

userLimit int(11)`

echo $limit->userLimit prints out nothing

Could this be related to a fact that database/table was created before we started to use RedBeanPHP ?

(btw, I have resolved this to switching all column names to lowercase, no problem fetching values after that)

gabordemooij commented 8 years ago

Sorry but you're code is not executable as-is, I have modified my version to look more like yours (I need a test case):

$l = R::dispense('limits');
$l->userLimit = 999;
$l->userid = 123;
$id = R::store($l);
$x = R::findOne('limits', 'userid=?', [123]);
var_dump($x->userLimit);

but this still works. Might have something to do with your DB config maybe ? What OS are you using?

nekromoff commented 8 years ago

HI, I am using standard MariaDB setup on Ubuntu 16.04 mysql Ver 15.1 Distrib 10.0.25-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

gabordemooij commented 8 years ago

Okay, now tested with MariaDB (10.0.23 over here) - still not able to reproduce the issue. I don't know why but it seems to work fine here, just as I expect. Can you verify that my latest code snippet above reproduces the error on your system?