Philipp Ott
2006-Mar-03 13:53 UTC
[Rails] AR::Base.pluralize_table_names doesnt work with scaffold generator, right?
Hi! The script/generator scaffold for models doesnt respect (source in) this config/environment.rb setup, right? Because I can put in there ActiveRecord::Base.pluralize_table_names = false but when I run a command like ruby script/generate scaffold model Something then it throws an error saying that my database scheme doesnt have a Something. However there is a table called something. If I then change my something table to somethings and rerun the command, then it works fine. Then I have to edit model/Somthing.rb and inlcude the set_table_name "Something" into the class definition, rename my table back to something and also fix the test-classes because they got generated with the somethings name. Seems to be a bit error prone to me and very unelegant. pgAdmin makes the sql part easy, but it still feels a bit strange to me. Wouldnt it be nice if this automatism could be turned off for the scaffold generator on request and we would be able to specify name of the Model, name-as-is of the table, and maybe even name-as-is of the primary key - and then the scaffold generator regards this and puts the set_table_name and set_primary_key instructions into the models? Or is there some way to tell this to the model generator already? BTW: set_table_name works for me just fine without the ActiveRecord::Base.pluralize_table_names = false assignment. In an empty rails project, if I manually create a model and tie it to a controller and view for editing and such, then use set_table_name, everything I m doing works. So my next question is: for what is this assignment then? How and when does it affect the model name to table name mapping? Regards Philipp