Accessing a table whose name is singular

Hello list,

I’m new to ActiveRecord. Actually, I’m using it outside of a rails
application (crazy I know). I have the following simple test code:

=============================================
require ‘rubygems’
require ‘activerecord’
require ‘yaml’

dbconfig = YAML::load_file(‘database.yml’)
ActiveRecord::Base.establish_connection(dbconfig)

class User < ActiveRecord::Base
end

ua = User.new()

where my database.yml file looks like

adapter: ‘mysql’
host: ‘localhost’
username: ‘myusername’
password: ‘mypassword’
database: ‘mysql’

I get the following error

Table ‘mysql.users’ doesn’t exist: SHOW FIELDS FROM users
(ActiveRecord::StatementInvalid)

The database I’m connecting to maintains a User table – note that the
name of the table is singular. How can I connect to a table that has
a name like User? ActiveRecord seems to append an ‘s’ character and
tries to connect to a Users table.

Thanks for any help
Robert

On Aug 5, 1:12 am, Robert [email protected] wrote:

The database I’m connecting to maintains a User table – note that the
name of the table is singular. How can I connect to a table that has
a name like User? ActiveRecord seems to append an ‘s’ character and
tries to connect to a Users table.
That is indeed the convention AR uses. You can use set_table_name to
override that.

Fred

Thanks!!

The syntax is

class User < ActiveRecord::Base
set_table_name ‘user’
end

On Aug 4, 5:30 pm, Frederick C. [email protected]