Database names

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?

James B. 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

James B. 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?

Think this is what you’re looking for:

http://wiki.rubyonrails.org/rails/pages/howtouselegacyschemas

Cheers
Luke