atman atta Fri Jun 03 10:49:07 -0400 2011

Subject: Why are tables expected to be plural? (End in 's' ?)


I am new to php.activerecord and it looks like the perfect framework for me. There is just one snag:

I have a model named User (User.php) and I want to access my data like so:


However I get the following exception:
42S02, 1146, Table 'myschema.users' doesn't exist

I have a table myschema.user that is defined...I did not request myschema.users table.

.... why is the framework changing my model name to be plural?

thank you!

Sjoerd van Heijst Sat Jun 04 05:33:49 -0400 2011


That is default functionality of the framework. All models are named in a singular form, the tables that they look for are the plural forms of that. If you don't want this behaviour, you can always specify the table it should use like this:

1 class User extends ActiveRecord\Model
2   {
3     # explicit table name since our table is not "users" 
4    static $table_name = 'user';
5  }

Hope that helped you out.

Yoan B Sat Jun 04 07:31:05 -0400 2011

Maybe can you dig to add this kind of configuration:

atman atta Sat Jun 11 18:55:02 -0400 2011

Thanks for your help!