mhoroschun-Hqix5oD4n6s0n/F98K4Iww@public.gmane.org
2007-Apr-30 04:06 UTC
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 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-30 14:26 UTC
Re: has_many :through polymorphic
http://blog.hasmanythrough.com/2006/4/3/polymorphic-through On 30/04/07, mhoroschun-Hqix5oD4n6s0n/F98K4Iww@public.gmane.org <mhoroschun-Hqix5oD4n6s0n/F98K4Iww@public.gmane.org> wrote:> > > 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. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
mhoroschun-Hqix5oD4n6s0n/F98K4Iww@public.gmane.org
2007-Apr-30 21:42 UTC
Re: has_many :through polymorphic
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. On May 1, 12:26 am, njmacin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> http://blog.hasmanythrough.com/2006/4/3/polymorphic-through > > On 30/04/07, mhorosc...-Hqix5oD4n6s0n/F98K4Iww@public.gmane.org <mhorosc...-Hqix5oD4n6s0n/F98K4Iww@public.gmane.org> wrote: > > > > > 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- Export CSV
- [PATCH 0/8] staging: hv: clean up forward declarations and camel cases in netvsc.c
- [PATCH 0/8] staging: hv: clean up forward declarations and camel cases in netvsc.c
- acts_as_list, move_higher, odd indexing behaviour?
- [PATCH NOT WORKING nbdkit] vddk: Restructure plugin to allow greater parallelism.