Arfon Smith
2008-Feb-14 17:38 UTC
ActiveRecord::HasManyThroughSourceAssociationNotFoundError
Hello there. I wonder if you could help with with an error I''m getting. I have a ''has_many through'' association in my application. I have a Batch model which has the following association: has_many :items, :through => :associations, :source => :item The Item model has the following association: has_many :batches, :through => :associations, :source => :batch I then have an Association model with the following: belongs_to :item belongs_to :batch The problem I have is that I am experiencing a intermitted error when making use of the association. Sometimes the association works (i.e. when looking up batch.items) and then other times the _same_ request fails with the error: ActiveRecord::HasManyThroughSourceAssociationNotFoundError (Could not find the source association(s) :batch in model Remote::Association. Try ''has_many :batches, :through => :associations, :source => <name>''. Is it one of :item or :project?): Basically the problem here is that sometimes the view that makes use of the association works and sometimes it doesn''t. All I have to do is keep hitting refresh on the browser and eventually the batch items are returned. Any ideas as to why I might be experiencing this error? Thanks arfon -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2008-Feb-14 17:55 UTC
Re: ActiveRecord::HasManyThroughSourceAssociationNotFoundError
On 14 Feb 2008, at 18:38, Arfon Smith wrote:> Hello there. I wonder if you could help with with an error I''m > getting. > > I have a ''has_many through'' association in my application. I have a > Batch model which has the following association: > > has_many :items, :through => :associations, :source => :item > > The Item model has the following association: > > has_many :batches, :through => :associations, :source => :batch > > I then have an Association model with the following: > > belongs_to :item > belongs_to :batch > > The problem I have is that I am experiencing a intermitted error when > making use of the association. Sometimes the association works (i.e. > when looking up batch.items) and then other times the _same_ request > fails with the error: > > ActiveRecord::HasManyThroughSourceAssociationNotFoundError (Could not > find the source association(s) :batch in model > Remote::Association. Try > ''has_many :batches, :through => :associations, :source => <name>''. Is > it one of :item or :project?): > > Basically the problem here is that sometimes the view that makes > use of > the association works and sometimes it doesn''t. All I have to do is > keep hitting refresh on the browser and eventually the batch items are > returned. > > Any ideas as to why I might be experiencing this error?Don''t think you need to add the two :source parameters as your associations follow conventions. However, my guess is "associations" is a reserved word in some way and that''s why you''re running into problems. Try replacing the associations table name with something else and see if it works that way. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Arfon Smith
2008-Feb-14 18:08 UTC
Re: ActiveRecord::HasManyThroughSourceAssociationNotFoundErr
Peter De Berdt wrote:> On 14 Feb 2008, at 18:38, Arfon Smith wrote: > >> has_many :batches, :through => :associations, :source => :batch >> >> returned. >> >> Any ideas as to why I might be experiencing this error? > > Don''t think you need to add the two :source parameters as your > associations follow conventions. However, my guess is "associations" > is a reserved word in some way and that''s why you''re running into > problems. Try replacing the associations table name with something > else and see if it works that way. > > > Best regards > > Peter De BerdtOK, I''ll try that. Originally I didn''t have the :source parameters but I put them in there to try and get around this intermitted error. Anyway, they didn''t fix anything! Will try renaming the Association model and table although I''m not sure why this would cause an intermittent error, if it was a reserved word I would have expected it to fail all the time... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2008-Feb-14 18:27 UTC
Re: ActiveRecord::HasManyThroughSourceAssociationNotFoundErr
On 14 Feb 2008, at 19:08, Arfon Smith wrote:> OK, I''ll try that. Originally I didn''t have the :source parameters > but > I put them in there to try and get around this intermitted error. > Anyway, they didn''t fix anything! > > Will try renaming the Association model and table although I''m not > sure > why this would cause an intermittent error, if it was a reserved > word I > would have expected it to fail all the time...Not necessarily, sometimes extra functionality is mixed in when you use certain methods. It could well be related to something like that. Unrelated to Rails or your problem, a similar case can happen if you name one your database fields "key" and you''re using mysql. Everything will go perfectly well until you are trying to use a condition on the field "key". Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Arfon Smith
2008-Feb-15 14:46 UTC
Re: ActiveRecord::HasManyThroughSourceAssociationNotFoundErr
Peter De Berdt wrote:> On 14 Feb 2008, at 19:08, Arfon Smith wrote: > >> OK, I''ll try that. Originally I didn''t have the :source parameters >> but >> I put them in there to try and get around this intermitted error. >> Anyway, they didn''t fix anything! >> >> Will try renaming the Association model and table although I''m not >> sure >> why this would cause an intermittent error, if it was a reserved >> word I >> would have expected it to fail all the time... > > Not necessarily, sometimes extra functionality is mixed in when you > use certain methods. It could well be related to something like that. > > Unrelated to Rails or your problem, a similar case can happen if you > name one your database fields "key" and you''re using mysql. > Everything will go perfectly well until you are trying to use a > condition on the field "key". > > > Best regards > > Peter De BerdtWell fingers crossed but it looks like your suggestion has fixed the error. I changed the Association model to Batchitem and the errors _seem_ to have gone away. Thanks for your help. Arfon -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Fri, 15 Feb 2008 15:46:44 +0100, Arfon Smith wrote:> Well fingers crossed but it looks like your suggestion has fixed the > error. I changed the Association model to Batchitem and the errors > _seem_ to have gone away. Thanks for your help.It''s hard to find a name for the join table! -Thufir --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---