This project is archived and is in readonly mode.

#736 ✓resolved
Justin Marney

has_many :through with custom primary keys

Reported by Justin Marney | July 31st, 2008 @ 09:43 PM | in 2.x

Given the following model:

Owner -has_many-> Bikes -has_many-> Spokes

class Owner

has_many :bikes

has_many :spokes, :through => :bikes

end

hmt will create an invalid sql statement for owner.spokes if set_primary_key is used. The source_primary_key was not pointing to the right primary key, but since all pks are 'id' in a normal rails model this problem was only seen when set_primary_key was used. This patch resolves the issue by changing the source_primary_key from @reflection.klass.primary_key to @reflection.through_reflection.klass.primary_key.

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages