This project is archived and is in readonly mode.

#2719 ✓resolved

has_many :through should work if the join model uses has_one relationship

Reported by sbwoodside | May 26th, 2009 @ 05:07 AM

Let's say you have User has_many Posts, and each Post has_one Photo. If you try to set a has_many :photos, :through :posts and then access you will get something like this:

ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source reflection macro :has_one for has_many :photos, :through => :posts.  Use :source to specify the source reflection.

Besides the fact that the error message isn't too helpful, it appears that this isn't supported in Rails 2.3.2 or previously. It would be awfully nice to be able to, for example, list all of the Photos for a certain User, etc.

There is an old bug in Rails Trac for this, which can no longer be modified.

It's not an uncommon problem: and and and

Is there a suggested workaround? (Aside from hacking SQL...)

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by