Rails: "generate model" with non-standard table name

R

Robert Eisig

Hi,

in rails I have to use an existing mysql table named "my_choice". It
does not follow the convention of tables being named plural.

To be able to use the "generate model" script I changed the following
in the file inflections.rb in the active_support lib (almost at the end
of the file):

inflect.uncountable(%w(equipment information [...] sheep my_choice))

I just added the table name at the end. After running the
"script/generate model my_choice" I removed it again.

(This resulted in correctly created files in test and db/migrate)

And then I added a line in the model that was just created:

class MyChoice < ActiveRecord::Base
set_table_name "my_choice"
end

Question: is this a good idea and the best possible way? Could I have
problems with this in the future working with it? How can I do this
easier when it happens again... ain't there a paramter for "generate
model" ? Something like "script/generate model --no-inflect my_choice"?

Thank you
Robert
 
G

gregarican

Robert said:
Hi,

in rails I have to use an existing mysql table named "my_choice". It
does not follow the convention of tables being named plural.


To be able to use the "generate model" script I changed the following
in the file inflections.rb in the active_support lib (almost at the end
of the file):


inflect.uncountable(%w(equipment information [...] sheep my_choice))


I just added the table name at the end. After running the
"script/generate model my_choice" I removed it again.


(This resulted in correctly created files in test and db/migrate)


And then I added a line in the model that was just created:


class MyChoice < ActiveRecord::Base
set_table_name "my_choice"
end


Question: is this a good idea and the best possible way? Could I have
problems with this in the future working with it? How can I do this
easier when it happens again... ain't there a paramter for "generate
model" ? Something like "script/generate model --no-inflect my_choice"?


Thank you
Robert



You might have better results posting this to the Rails mailing list at


http://lists.rubyonrails.org/mailman/listinfo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,206
Messages
2,571,068
Members
47,674
Latest member
scazeho

Latest Threads

Top