James Bond wrote:> If I generate a model by: "./script generate model user" it make
a table
> "users".
> But if I want that table is "user" not "users" what I
can do?
You can override the default table name in your migration file after
running the generator.
However, if I had anything to say about it I would not allow a developer
to break this Rails convention. The only allowable exception would be in
the case of a pre-existing database schema that is being used somewhere
outside the Rails project.
But, if you want to go to all the extra trouble to break with
convention, Rails will certainly let you do so.
You need to change the table name in the migration and also set the
table name in the model so it knows what to look for:
Example:
-------------------
class Project < ActiveRecord::Base
set_table_name "project"
end
class CreateProjects < ActiveRecord::Migration
def self.up
create_table :project do |t| # Note singular form
t.string :name
t.text :description
t.timestamps
end
end
def self.down
drop_table :project # And here too
end
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---