# Accessing a table whose name is singular

**URL:** <https://www.ruby-forum.com/t/accessing-a-table-whose-name-is-singular/144999>\
**Category:** Rails\
**Created:** [August 5, 2008, 2:30am UTC](https://www.ruby-forum.com/t/accessing-a-table-whose-name-is-singular/144999 "2008-08-05T02:30:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@robert](https://www.ruby-forum.com/u/robert)\
**Post date:** [August 5, 2008, 2:30am UTC](https://www.ruby-forum.com/t/accessing-a-table-whose-name-is-singular/144999/1 "2008-08-05T02:30:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@robert](https://www.ruby-forum.com/u/robert)\
**Post date:** [August 5, 2008, 2:31am UTC](https://www.ruby-forum.com/t/accessing-a-table-whose-name-is-singular/144999/2 "2008-08-05T02:31:11Z")

</div>

On Aug 5, 1:12 am, Robert [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![robert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@robert](https://www.ruby-forum.com/u/robert)\
**Post date:** [August 5, 2008, 3:04am UTC](https://www.ruby-forum.com/t/accessing-a-table-whose-name-is-singular/144999/3 "2008-08-05T03:04:30Z")

</div>

Thanks!!

The syntax is

class User \< ActiveRecord::Base  
set\_table\_name ‘user’  
end

On Aug 4, 5:30 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
