hdorio
hdorio

Reputation: 13333

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

Upvotes: 5

Views: 852

Answers (2)

mpechner
mpechner

Reputation: 261

If it is only specific tables and not all of them

self.pluralize_table_names = false

works well.

Upvotes: 2

Roman Gonzalez
Roman Gonzalez

Reputation: 1931

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.

Upvotes: 7

Related Questions