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.

This project is archived and is in readonly mode.

has_many :through with :conditions fails

#3316

From Stackoverflow ("Eric"): http://stackoverflow.com/questions/1514880/how-can-i-create-new-rec...

I would put the models in here but Lighthouse's formatting is so sporadic that it munges it.

Given the models in: http://github.com/radar/course-student-membership-bug

When I run "rake observer" I get:

Membership(#2174755620) expected, got Array(#2148226700)

I haven't yet investigated where the array is coming from, perhaps after breakfast.

Reported by Ryan Bigg · October 3rd, 2009 @ 11:47 PM

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Ryan Bigg
    Ryan Bigg

    Upon further investigation it appears that changing the conditions line from:

    :conditions => { :memberships => { :observer => true }}
    

    to

    :conditions => ["memberships.observer = ?", true]
    

    fixes the problem.

    The association.replace() call around line #1322 of associations.rb passes in a hash where it appears it should be passing in an array. The caller chain of this leads me to attributes= on line #2732 of base.rb, which gets the key of "memberships" having the value of {:observer => true }. With the Array conditions hash this never occurs, the only output I see from this method is the "name" key having a value of "Joe Student".

    October 4th, 2009 @ 12:35 AM

  2. John Trupiano
    John Trupiano

    If I'm not mistaken, this is a duplicate of #2998 ( https://rails.lighthouseapp.com/projects/8994/tickets/2998-named_sc... ) for which I've submitted a patch. A +1 there would be helpful.

    October 4th, 2009 @ 12:49 AM

  3. Ryan Bigg
    Ryan Bigg
    • State changed from new to duplicate

    Duplicate of #2998.

    June 23rd, 2010 @ 01:27 PM