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

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

Peter De Berdt wrote:

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

Peter De Berdt wrote:

It's hard to find a name for the join table!