# \[ActiveRecord\] How to automatically bind, for example, :rows with Row or :user\_id with User?

**URL:** <https://www.ruby-forum.com/t/activerecord-how-to-automatically-bind-for-example-rows-with-row-or-user-id-with-user/158651>\
**Category:** Rails\
**Created:** [January 26, 2009, 1:51pm UTC](https://www.ruby-forum.com/t/activerecord-how-to-automatically-bind-for-example-rows-with-row-or-user-id-with-user/158651 "2009-01-26T13:51:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Pierre\_L](https://www.ruby-forum.com/u/Pierre_L)\
**Post date:** [January 26, 2009, 1:51pm UTC](https://www.ruby-forum.com/t/activerecord-how-to-automatically-bind-for-example-rows-with-row-or-user-id-with-user/158651/1 "2009-01-26T13:51:49Z")

</div>

Hello,

Imagine that I have the two following models :  
class A \< ActiveRecord::Base  
belongs\_to :b, :foreign =\> :fkey  
end

class B \< ActiveRecord::Base  
end

Is it possible to retrieve both classes A and B and that column fkey  
is pointing to table B ? In other words, if I give :a and :fkey, how  
to obtain the class A and the fact that ‘fkey’ is a foreign key  
pointing to table ‘B’ ?  
I am almost sure that AR can do that, but this is not well-documented,  
and source-code is a bit obsucated…

Thank you in advance,  
Pierre L.

---

<div class="post-metadata">

**Author:** ![Pierre\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Pierre\_L](https://www.ruby-forum.com/u/Pierre_L)\
**Post date:** [January 26, 2009, 1:56pm UTC](https://www.ruby-forum.com/t/activerecord-how-to-automatically-bind-for-example-rows-with-row-or-user-id-with-user/158651/2 "2009-01-26T13:56:33Z")

</div>

On 25 Jan 2009, at 23:08, Pierre L wrote:

> Is it possible to retrieve both classes A and B and that column fkey  
> is pointing to table B ? In other words, if I give :a and :fkey, how  
> to obtain the class A and the fact that ‘fkey’ is a foreign key  
> pointing to table ‘B’ ?

If you’re looking to introspect what associations have been setup then  
you’d want to look at A.reflections.

Fred

---

<div class="post-metadata">

**Author:** ![Pierre\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Pierre\_L](https://www.ruby-forum.com/u/Pierre_L)\
**Post date:** [January 27, 2009, 8:33pm UTC](https://www.ruby-forum.com/t/activerecord-how-to-automatically-bind-for-example-rows-with-row-or-user-id-with-user/158651/3 "2009-01-27T20:33:16Z")

</div>

Thank you !
