This project is archived and is in readonly mode.
Has Many Association With Conditions And Dependant Throws Error
Reported by Danny Tipple | December 16th, 2009 @ 01:08 PM | in 2.3.9
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
Comments and changes to this ticket
-
Sascha Konietzke January 3rd, 2010 @ 09:30 AM
I can confirm this, the same error occurred for me when upgrading to 2.3.5.
-
Danny Tipple February 3rd, 2010 @ 02:06 PM
- Tag changed from activerecord, has_many to activerecord, active_record, has_many
-
Danny Tipple May 19th, 2010 @ 02:52 PM
This is actually fixed in 3.0 beta3 but still broken in the 2.3 branch.
-
Rizwan Reza May 20th, 2010 @ 03:17 PM
- no changes were found...
-
Rizwan Reza May 21st, 2010 @ 12:41 AM
- no changes were found...
-
Rizwan Reza May 21st, 2010 @ 01:04 AM
- Milestone set to 2.3.6
-
Grant Ammons July 6th, 2010 @ 11:17 PM
- 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.
-
Neeraj Singh July 13th, 2010 @ 11:00 AM
- 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.
-
José Valim July 14th, 2010 @ 07:10 AM
- 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.
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>