Pluralizing is not Perfect
27 Sep 2012
Adding an s to the end of something does not necessarily make it plural.
I was running my specs in my Sinatra app and I kept seeing this error...
1 Failure/Error: gr.save(id,data) 2 ActiveRecord::StatementInvalid: 3 PG::Error: ERROR: relation "gamedata" does not exist 4 LINE 4: WHERE a.attrelid = '"gamedata"'::regclass 5 ^ 6 : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull 7 FROM pg_attribute a LEFT JOIN pg_attrdef d 8 ON a.attrelid = d.adrelid AND a.attnum = d.adnum 9 WHERE a.attrelid = '"gamedata"'::regclass 10 AND a.attnum > 0 AND NOT a.attisdropped 11 ORDER BY a.attnum 12
The problem was in the pluralization. My migration name was Create_Gamedata. Using the convention I thought was correct, while writing my migration I used
1 create_table :gamedatas do |t| 2
from examples I had seen, it seemed that you should always just add an s.
That is where the problem lies. The word data is actually already plural. Here is a solution to this problem...
1 self.table_name = 'gamedatas' 2
In my gamedata model, I added the self.table_name = 'gamedatas' line to point to the right table.