# Obtaining table information from "belongs\_to"? (reflection?)

**URL:** <https://www.ruby-forum.com/t/obtaining-table-information-from-belongs-to-reflection/89320>\
**Category:** Rails\
**Created:** [March 19, 2007, 3:43pm UTC](https://www.ruby-forum.com/t/obtaining-table-information-from-belongs-to-reflection/89320 "2007-03-19T15:43:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9e8a1a/32.png) [@Vic](https://www.ruby-forum.com/u/Vic)\
**Post date:** [March 19, 2007, 3:43pm UTC](https://www.ruby-forum.com/t/obtaining-table-information-from-belongs-to-reflection/89320/1 "2007-03-19T15:43:03Z")

</div>

Hi all,

How would one obtain the database table name if given a column name?  
Does ActiveRecord know how to do that?

For example if there is a model that “belongs\_to :myobject\_id”, is there  
a way to get the table name from “myobject\_id” ?

Thank you,  
Vic

---

<div class="post-metadata">

**Author:** ![Vic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9e8a1a/32.png) [@Vic](https://www.ruby-forum.com/u/Vic)\
**Post date:** [March 20, 2007, 10:06am UTC](https://www.ruby-forum.com/t/obtaining-table-information-from-belongs-to-reflection/89320/2 "2007-03-20T10:06:10Z")

</div>

On Mar 19, 7:43 am, Vic [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How would one obtain the database table name if given a column name?  
> Does ActiveRecord know how to do that?

> From [http://railsmanual.org/module/ActiveRecord::Reflection::ClassMethods/reflect\_on\_association/1.1.2](http://railsmanual.org/module/ActiveRecord::Reflection::ClassMethods/reflect_on_association/1.1.2)

“”"  
Returns the AssociationReflection object for the named aggregation  
(use the symbol). Example:

Account.reflect\_on\_association(:owner) # returns the owner  
AssociationReflection  
Invoice.reflect\_on\_association(:line\_items).macro #  
returns :has\_many  
“”"

Then you should be able to call table\_name() on the  
AssociationReflection:  
Account.reflect\_on\_association(:owner).table\_name # returns ‘account’

Kevin
