How can I prevent Rails from "pluralizing" a column name?
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2010-03-11T23:52:40Z
Indexed on
2010/03/12
2:07 UTC
Read the original article
Hit count: 512
I'm using dwilkie's foreigner plugin for rails. I have a table creation statement that looks like:
create_table "agents_games", :force => true, :id => false do |t|
t.references :agents, :column => :agent_id, :foreign_key => true, :null => false
t.references :games, :column => :game_id, :foreign_key => true, :null => false
end
However, this generates the following SQL:
[4;35;1mSQL (2.7ms)[0m [0mCREATE TABLE "agents_games" ("agents_id" integer NOT NULL, "games_id" integer NOT NULL) [0m
I want the columns to be called agent_id
and game_id
- not agents_id
and agent_id
. How can I prevent Rails from pluralizing the columns?
I tried the following in my enviornment.rb
file, which didn't help:
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable "agent_id", "game_id"
end
© Stack Overflow or respective owner