gabordemooij / redbean

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

why does rb remove the letter "s" at the end of the table name during crud operations in freeze mode #912

Closed relaxdd closed 1 year ago

relaxdd commented 1 year ago

after I designed my tables and corrected their types, I decided that it was possible to freeze redbeanphp and ran into an unexpected problem, it started deleting the letter 's' at the end of my tables' names during crud operations, my tables are called 'users', 'configs' and 'tokens'

the simplest solution is most likely to just rename the tables, but why have to I do that?

gabordemooij commented 1 year ago

RedBeanPHP does not do such thing I believe, are you sure? Can you show me a simple test case?

gabordemooij commented 1 year ago

The following code seems to work just fine:


$user = R::dispense('user');
$user->name = 'me';
R::store($user);
print_r(R::inspect());

Gives a table "user":

Array
(
    [0] => user
)
relaxdd commented 1 year ago

why are you creating a "dispense" component named "user", I said about "users"

чт, 16 февр. 2023 г. в 02:53, Gabor de Mooij @.***>:

The following code seems to work just fine:

$user = R::dispense('user'); $user->name = 'me'; R::store($user); print_r(R::inspect());

Gives a table "user":

Array ( [0] => user )

— Reply to this email directly, view it on GitHub https://github.com/gabordemooij/redbean/issues/912#issuecomment-1432185074, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKWKDPBGSMUK2QD7CGR67ADWXVM6RANCNFSM6AAAAAAUFN3RQU . You are receiving this because you authored the thread.Message ID: @.***>

gabordemooij commented 1 year ago

Okay, my bet, sorry, I read it wrong.

But still:


$user = R::dispense('users');
$user->name = 'me';
R::store($user);
print_r(R::inspect());

gives:

Array
(
    [0] => users
)

I am not really a fan of automatic inflection, so I would never implement anything like that in RedBeanPHP. Can you give me a counter example like this that demonstrates the issue?

gabordemooij commented 1 year ago

This also just works fine over here?

$user = R::dispense('users');
$user->name = 'me';
R::store($user);
R::freeze(1);
print_r(R::find('users'));
Lynesth commented 1 year ago

after I designed my tables

Did you manually rename your tables to plural versions of the words? Redbean will not add or remove s at the end of the tables. As Gabor mentioned, It doesn't do the whole user -> users, person -> people inflections that some other ORMs do.

relaxdd commented 1 year ago

I will try to show an example in the near time, there is a lot of work now, at that moment I just renamed my tables from "users" to "user" and so on, but I remember for sure that there were problems with the action "R::dispense('users')" or "R::find('users')" I was receiving an error saying that the "user" table does not exist, that is, he was looking for or trying to create without the letter "s" at the end of the table name, and this was happening only in the "freeze" mode

gabordemooij commented 1 year ago

I am pretty sure I never wrote such logic, but I will test it anyway.

relaxdd commented 1 year ago

This also just works fine over here?

$user = R::dispense('users');
$user->name = 'me';
R::store($user);
R::freeze(1);
print_r(R::find('users'));

For some reason, this does not work for me personally, it gives the error "the 'user' table was not found, despite the fact that I actually wrote 'users' in the code"

relaxdd commented 1 year ago

after I designed my tables

Did you manually rename your tables to plural versions of the words? Redbean will not add or remove s at the end of the tables. As Gabor mentioned, It doesn't do the whole user -> users, person -> people inflections that some other ORMs do.

I have it happening for some reason ""SQLSTATE[42S02]: Base table or view not found: 1146 Table 'table-name.user' doesn't exist""

relaxdd commented 1 year ago

I am pretty sure I never wrote such logic, but I will test it anyway.

is it possible that PDO does this?