# Table name of an object

**URL:** <https://www.ruby-forum.com/t/table-name-of-an-object/87542>\
**Category:** Rails\
**Created:** [March 3, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/table-name-of-an-object/87542 "2007-03-03T17:12:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [March 3, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/table-name-of-an-object/87542/1 "2007-03-03T17:12:10Z")

</div>

Hello,

how can I find out the table name of an object?

For example I have the object ua of the class UserArticle:  
ua = UserArticle.find(1)

How can I find out it is saved in the table user\_articles?

---

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [March 3, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/table-name-of-an-object/87542/2 "2007-03-03T18:11:23Z")

</div>

2007/3/3, rv dh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

Hi,

> how can I find out the table name of an object?
> 
> For example I have the object ua of the class UserArticle:  
> ua = UserArticle.find(1)
> 
> How can I find out it is saved in the table user\_articles?

With AR::B.table\_name :

UserArticle.table\_name

# =\> “user\_articles”

If you have the name of the class in a string and you’re  
following Rails conventions (and assuming you haven’t a prefix  
or a suffix), then you can write :

‘UserArticle’.tableize

# =\> “user\_articles”

– Jean-François.

–  
Ruby ( [http://www.rubyfrance.org](http://www.rubyfrance.org) ) on Rails ( [http://www.railsfrance.org](http://www.railsfrance.org)  
)

---

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [March 3, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/table-name-of-an-object/87542/3 "2007-03-03T18:17:16Z")

</div>

Thank you Jean-FranÃ§ois. I just found out that it is this easy:

> > UserArticle.table\_name  
> > =\> “user\_article”

---

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [March 3, 2007, 6:22pm UTC](https://www.ruby-forum.com/t/table-name-of-an-object/87542/4 "2007-03-03T18:22:48Z")

</div>

rv dh wrote:

> Thank you Jean-FranÃ§ois. I just found out that it is this easy:
> 
> > > UserArticle.table\_name  
> > > =\> “user\_article”

This is not what I initially asked for, of course. I meant to say it is  
as easy as this:

ua = UserArticle.find(1)  
ua.class.to\_s.tableize
