#1 new

Wrong ID for has_many :through on a belongs_to relationship

Reported by Jonathan | October 27th, 2008 @ 12:16 AM

class Group < ActiveRecord::Base belongs_to :network has_many :users, :through => :network end

Group.first.users will form this SQL Query

..... WHERE ( networks.id = 1 )

In which 1 is the id of the GROUP, not the NETWORK! Big problem.

Comments and changes to this ticket

  • Ian White

    Ian White October 27th, 2008 @ 10:57 AM

    nested_has_many_through hasn't yet been tested on belongs_to (it's target has always been through has_many), so thanks for the bug report.

    I'm currently very busy, but will get around to this. In the meantime, a spec highlighting the problem, or even better, a speced patch fixing the problem, would be very welcome.

  • Emery Finkelstein

    Emery Finkelstein February 19th, 2010 @ 11:33 PM

    I've got a patch for this, and I'm writing a spec now. Expect a pull request in an hour or so.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

People watching this ticket