# Belongs\_to :through

**URL:** <https://www.ruby-forum.com/t/belongs-to-through/184934>\
**Category:** Rails\
**Created:** [March 10, 2010, 3:56pm UTC](https://www.ruby-forum.com/t/belongs-to-through/184934 "2010-03-10T15:56:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joahking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90db22/32.png) [@joahking](https://www.ruby-forum.com/u/joahking)\
**Post date:** [March 10, 2010, 3:56pm UTC](https://www.ruby-forum.com/t/belongs-to-through/184934/1 "2010-03-10T15:56:20Z")

</div>

hi there,  
lets say you have: A that belongs\_to :b, and B belongs\_to :c

how do you normally go about saying A belongs\_to :c, :through =\> :b ??

searching I found two solutions:

1. method:  
class A  
def c  
b.c  
end  
end

and

2.delegate:  
class A  
delegate :c, :to =\> :b  
end

but neither will have the benefits of generated sql with joins.

How you normally do this? and What are the reasons against having it on  
rails itself?

greetings  
joaquin

–

> **[Least Significant Bit](http://www.least-significant-bit.com)**
>
> The blog of Joaquin Rivera Padron (@joahking). Here I share my thoughts about programming, architecture, scalability, Open Source, Ruby, Testing, BDD, linux and more.

---

<div class="post-metadata">

**Author:** ![joahking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90db22/32.png) [@joahking](https://www.ruby-forum.com/u/joahking)\
**Post date:** [March 10, 2010, 4:07pm UTC](https://www.ruby-forum.com/t/belongs-to-through/184934/2 "2010-03-10T16:07:57Z")

</div>

Joaquin Rivera padron wrote:

> hi there,  
> lets say you have: A that belongs\_to :b, and B belongs\_to :c
> 
> how do you normally go about saying A belongs\_to :c, :through =\> :b ??

If A belongs\_to :b, that means that Rails expects a b\_id field in A’s  
table. In your case, that doesn’t exist, so what you want is  
A has\_one :c, :through =\> :b

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![joahking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/90db22/32.png) [@joahking](https://www.ruby-forum.com/u/joahking)\
**Post date:** [March 10, 2010, 6:14pm UTC](https://www.ruby-forum.com/t/belongs-to-through/184934/3 "2010-03-10T18:14:56Z")

</div>

Marnen Laibow-Koser wrote:

> Joaquin Rivera padron wrote:
> 
> > hi there,  
> > lets say you have: A that belongs\_to :b, and B belongs\_to :c
> > 
> > how do you normally go about saying A belongs\_to :c, :through =\> :b ??
> 
> If A belongs\_to :b, that means that Rails expects a b\_id field in A’s  
> table. In your case, that doesn’t exist, so what you want is  
> A has\_one :c, :through =\> :b

Wow, that was stupid of me. I must not have been awake when I wrote  
that. has\_one :through will probably work, but my explanation is  
totally inaccurate. Sorry.

> ## Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid
