Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Wrong ID for has_many :through on a belongs_to relationship

#1

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.

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

State: new
Milestone: none
Assigned to: Ian White Ian White

Activity

  1. Ian White
    Ian White

    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.

    October 27th, 2008 @ 10:57 AM

  2. Emery Finkelstein
    Emery Finkelstein

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

    February 19th, 2010 @ 11:33 PM

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.