Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override all table name convention in ActiveRecord

My project doesn't use the plural convention in table's names. How can I override this convention without calling set_table_name in all my ActiveRecord class

like image 365
hdorio Avatar asked Feb 11 '10 18:02

hdorio


2 Answers

You have to create an initializer in your rails project like this:

# file: config/initializers/active_record_extensions.rb

ActiveRecord::Base.pluralize_table_names = false

This will make all your table names singular by default on your models.

like image 194
Roman Gonzalez Avatar answered Oct 02 '22 09:10

Roman Gonzalez


If it is only specific tables and not all of them

self.pluralize_table_names = false

works well.

like image 25
mpechner Avatar answered Oct 02 '22 09:10

mpechner