Forum: Ruby on Rails has_many :through polymorphic

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F69b9307bdfbf9294f05f4fb5424cccf?d=identicon&s=25 (Guest)
on 2007-04-30 06:08
(Received via mailing list)
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 = 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 =

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


D5145c421cd25af6fa577c15219add90?d=identicon&s=25 unknown (Guest)
on 2007-04-30 16:27
(Received via mailing list)
F69b9307bdfbf9294f05f4fb5424cccf?d=identicon&s=25 (Guest)
on 2007-04-30 23:43
(Received via mailing list)
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 topic is locked and can not be replied to.