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 Association With Conditions And Dependant Throws Error

#3580

When using a has many association with both conditions and dependent params a "wrong number of arguments (2 for 1)" error is thrown in activerecord-2.3.5/lib/active_record/associations.rb line 1416

One such example of this is..

has_many :comments, :foreign_key => 'commentable_id', :conditions => "commentable_type = 'User'", :dependent => :destroy

Simliar happens with..

has_many :comments, :foreign_key => 'commentable_id', :conditions => {:commentable_type => 'User'}, :dependent => :destroy

Reported by Danny Tipple · December 16th, 2009 @ 01:08 PM

State: duplicate
Milestone: 2.3.9
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Sascha Konietzke
    Sascha Konietzke

    I can confirm this, the same error occurred for me when upgrading to 2.3.5.

    January 3rd, 2010 @ 09:30 AM

  2. Danny Tipple
    Danny Tipple
    • Tag changed from activerecord, has_many to activerecord, active_record, has_many

    February 3rd, 2010 @ 02:06 PM

  3. Danny Tipple
    Danny Tipple

    This is actually fixed in 3.0 beta3 but still broken in the 2.3 branch.

    May 19th, 2010 @ 02:52 PM

  4. Rizwan Reza
    Rizwan Reza
    • No changes were found…

    May 20th, 2010 @ 03:17 PM

  5. Rizwan Reza
    Rizwan Reza
    • No changes were found…

    May 21st, 2010 @ 12:41 AM

  6. Rizwan Reza
    Rizwan Reza
    • Milestone set to 2.3.6

    May 21st, 2010 @ 01:04 AM

  7. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.6 to 2.3.7

    May 23rd, 2010 @ 05:54 PM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.7 to 2.3.8

    May 24th, 2010 @ 09:40 AM

  9. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.8 to 2.3.9

    May 25th, 2010 @ 11:45 PM

  10. Grant Ammons
    Grant Ammons
    • Importance changed from to High

    I believe this is fixed in 2.3.8. I created some tests around the bug and indeed it is a problem in the 2.3.5 branch, however the test passes cleanly in 2.3.8 and 2-3-stable.

    Patch attached, against 2-3-stable branch. Also applies cleanly to v2.3.8, however needs a bit if finagling to apply to 2.3.5.

    July 6th, 2010 @ 11:17 PM

  11. Neeraj Singh
    Neeraj Singh
    • State changed from new to open
    • Tag changed from activerecord, active_record, has_many to activerecord, active_record, has_many, patch
    • Assigned user set to José Valim
    • Importance changed from High to Low

    +1

    applied this patch in 2-3-stable branch and all the tests are passing.

    July 13th, 2010 @ 11:00 AM

  12. José Valim
    José Valim
    • State changed from open to duplicate

    It would be appropriate to find out when it got fixed and if the original fix already included tests (it probably did). Particularly, the current test name in the patch: test_has_many_associations_thingy could be improved, since it does not reveal any intent.

    July 14th, 2010 @ 07:10 AM