ActiveRecord infers database table names based on class names. : Assumption from ActiveRecord « ActiveRecord « Ruby






ActiveRecord infers database table names based on class names.



It assumes the existence of certain database columns.
The first assumption of an Active Record class is the table name. 
In the case of our Account class, the table Active Record assumes is accounts. It makes this assumption based on the following guidelines:

The name of the table within the database is the pluralized name of the class defined in your Active Record program. 

The table name is in lowercase. 

If the class name includes multiple words that begin with capital letters, the words will be separated by underscores in the table name.


Examples of Active Record Table Pluralization


Class Name         Table Name

Account            accounts

Person             people

UserImage          user_images

Address            addresses

Currency           currencies

Mouse              mice

In addition, Active Record also assumes that each table has an automatically 
incremented integer primary key column named id.

 








Related examples in the same category

1.If you want table names to be singular instead of plural, you can set the configuration parameter pluralize_table_names:
2.id is default for autoincrease