# Has\_many :through polymorphic

**URL:** <https://www.ruby-forum.com/t/has-many-through-polymorphic/93262>\
**Category:** Rails\
**Created:** [April 30, 2007, 6:08am UTC](https://www.ruby-forum.com/t/has-many-through-polymorphic/93262 "2007-04-30T06:08:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 30, 2007, 6:08am UTC](https://www.ruby-forum.com/t/has-many-through-polymorphic/93262/1 "2007-04-30T06:08:06Z")

</div>

Hi All,

I have the following arrangement:

class PickAndPackRequest \< ActiveRecord::Base  
has\_many :transactions, :as =\> :request  
has\_many :postings, :through =\> :transactions  
end

class Transaction \< ActiveRecord::Base  
belongs\_to :request, :polymorphic =\> true  
has\_many :postings  
end

class Posting \< ActiveRecord::Base  
belongs\_to :transaction  
end

But when I ask for PickAndPackRequest.find(:first).postings.find(:all)  
it fails with:

Mysql::Error: Unknown column ‘transactions.transaction\_id’ in ‘on  
clause’

It generates the following SQL (which appears to be incorrect):

SELECT postings.\* FROM postings INNER JOIN transactions ON  
postings.id = transactions.transaction\_id WHERE  
((transactions.request\_id = 14) AND (transactions.request\_type =  
‘PickAndPackRequest’))

The “ON” clause appears to be wrong, I would have thought it would be:

```
ON postings.transaction_id = transaction.id

```

Can anybody point out what I’m doing wrong, because I’m stumped!

Cheers

Matthew.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 30, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/has-many-through-polymorphic/93262/2 "2007-04-30T16:27:48Z")

</div>

[http://blog.hasmanythrough.com/2006/4/3/polymorphic-through](http://blog.hasmanythrough.com/2006/4/3/polymorphic-through)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 30, 2007, 11:43pm UTC](https://www.ruby-forum.com/t/has-many-through-polymorphic/93262/3 "2007-04-30T23:43:58Z")

</div>

Thanks for the reply, however I’m pretty confident that this isn’t the  
case that is covered in that article.

The article is talking about “the other side of” a  
polymorphic :through. That’s not what I’ve got. If I was asking for  
all the Requests of a Transaction (of which there are many kinds of  
Request) then that would be “the other side” and could be solved as  
suggested in the article.

Cheers

Matthew.
