gabordemooij / redbean

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

R::findOneOrDispense (and maybe others) skips type validation #546

Closed josejulio closed 7 years ago

josejulio commented 7 years ago
R::dispense('buy_from');

Will throw 'RedBeanPHP\RedException' with message 'Invalid type: buy_from'

While

R::findOneOrDispense('buy_from', 'key = :key', array('key' => 'disable_type_checking'));

Doesn't throw any exception and creates the table buy_from.

While _ isn't officially supported, it works on my sharedList by using this hidden feature. e.g.

$item->sharedBuyFromList[] = $buyFrom;

Is there any reason that _ isn't officially supported? I don't recall reading about it on the site.

hausl commented 7 years ago

While R::findOneOrDispense('buy_from', 'key = :key', array('key' => 'disable_type_checking')); Doesn't throw any exception and creates the table buy_from.

That seems to me beeing a bug.

Is there any reason that _ isn't officially supported? I don't recall reading about it on the site.

See here:

In RedBeanPHP, the underscore '_' is used to denote a relation between two tables. http://www.redbeanphp.com/index.php?p=/prefixes -> "Prefixes"

$page = R::dispense( 'cms_page' ); //invalid: _ http://www.redbeanphp.com/index.php?p=/crud -> "Conventions"

josejulio commented 7 years ago

I don't know how i missed that part, thank you!

hausl commented 7 years ago

R::findOneOrDispense('buy_from', 'key = :key', array('key' => 'disable_type_checking')); Doesn't throw any exception and creates the table buy_from.

@gabordemooij, isn't this a bug?

gabordemooij commented 7 years ago

Okay, sorry my fault, I will look into this.

gabordemooij commented 7 years ago

This issue has been fixed in the master branch.