# ActiveRecord.find - Association Not Found Error When Using Custom Joins

**URL:** <https://www.ruby-forum.com/t/activerecord-find-association-not-found-error-when-using-custom-joins/189783>\
**Category:** Rails\
**Created:** [June 7, 2010, 6:03pm UTC](https://www.ruby-forum.com/t/activerecord-find-association-not-found-error-when-using-custom-joins/189783 "2010-06-07T18:03:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![neufelni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e68b1a/32.png) [@neufelni](https://www.ruby-forum.com/u/neufelni)\
**Post date:** [June 7, 2010, 6:03pm UTC](https://www.ruby-forum.com/t/activerecord-find-association-not-found-error-when-using-custom-joins/189783/1 "2010-06-07T18:03:31Z")

</div>

Hello,

When calling the find method on one of my models, I am joining to  
several other table using the :joins parameter. Currently, the :joins  
parameter is being populated with an array of several associations.  
However, I need to add a custom join, but when I add a string with my  
custom join to the joins array, I get the following error:

Association named ’ INNER JOIN … ’ was not found; perhaps you  
misspelled it?

According to the documentation found here:  
[ActiveRecord::Base](http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001777),  
the :joins parameter can contains “an array containing a mixture of  
both strings and named associations.” That is exactly what I’m doing,  
so I’m not sure why I’m getting this error when trying to combing  
them.

Any ideas why this error would occur?

Thanks,  
neufelni

---

<div class="post-metadata">

**Author:** ![neufelni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e68b1a/32.png) [@neufelni](https://www.ruby-forum.com/u/neufelni)\
**Post date:** [June 7, 2010, 6:12pm UTC](https://www.ruby-forum.com/t/activerecord-find-association-not-found-error-when-using-custom-joins/189783/2 "2010-06-07T18:12:53Z")

</div>

On Jun 7, 4:46 pm, neufelni [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> According to the documentation found here:[ActiveRecord::Base](http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001777),  
> the :joins parameter can contains “an array containing a mixture of  
> both strings and named associations.” That is exactly what I’m doing,  
> so I’m not sure why I’m getting this error when trying to combing  
> them.
> 
> Any ideas why this error would occur?

A cursory look at the code suggests that nothing is being done to  
handle the case of a mixture of strings & named associations.

Fred

---

<div class="post-metadata">

**Author:** ![neufelni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e68b1a/32.png) [@neufelni](https://www.ruby-forum.com/u/neufelni)\
**Post date:** [June 7, 2010, 6:13pm UTC](https://www.ruby-forum.com/t/activerecord-find-association-not-found-error-when-using-custom-joins/189783/3 "2010-06-07T18:13:50Z")

</div>

Well, example code, yours to be exact, would help in diagnosing the  
issue…

Otherwise, it’s simply ‘you must have implemented something incorrectly’

---

<div class="post-metadata">

**Author:** ![neufelni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e68b1a/32.png) [@neufelni](https://www.ruby-forum.com/u/neufelni)\
**Post date:** [June 8, 2010, 3:07pm UTC](https://www.ruby-forum.com/t/activerecord-find-association-not-found-error-when-using-custom-joins/189783/4 "2010-06-08T15:07:30Z")

</div>

It looks like you are right Fred, the code doesn’t actually handle a  
mixture of strings and associations. I found the following patch to  
fix the problem:  
[http://groups.google.ca/group/rubyonrails-core/browse\_thread/thread/50339b16ca736500](http://groups.google.ca/group/rubyonrails-core/browse_thread/thread/50339b16ca736500)

Thanks,  
neufelni

On Jun 7, 12:11 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
