Has_many :through polymorphic

Hi All,

I have the following arrangement:

class PickAndPackRequest < ActiveRecord::Base
has_many :transactions, :as => :request
has_many :postings, :through => :transactions

class Transaction < ActiveRecord::Base
belongs_to :request, :polymorphic => true
has_many :postings

class Posting < ActiveRecord::Base
belongs_to :transaction

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

Mysql::Error: Unknown column ‘transactions.transaction_id’ in ‘on

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 =

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!




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.



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs