This project is archived and is in readonly mode.
has_many through belongs_to association bug
-
Bogdan Gusiev
- Tag changed from activerecord associations, activerecord to activerecord associations, activerecord, patch
Here is my patch. Hopefully won't cause any side effects.
-
DHH
- Assigned user set to Pratik
-
Andrew White
- Assigned user changed from Pratik to Andrew White
- State changed from new to open
- Milestone cleared.
- Importance changed from to High
Someone else has reported this on #4977 Calling 'size' on an 'has_many :through' association errors. Definitely need to fix this before final release. Should return an empty array if the belongs_to association is nil.
-
Bogdan Gusiev
Hey Andrew,
Thanks for taking care about this.
I have fixed the bug by redefining costruct_scope method and return "empty" scope in case of nil association.
{:find => {:conditions => "1!=1"}} seems the only one way of creating an always empty scope that works on MySQL, sqlite and postgres.Here is my updated patch where tests are in the right place.
Thanks,
Bogdan. -
Andrew White
- State changed from open to needs-more-info
- Importance changed from High to Low
I can't reproduce this - can you post a sample application where this fails? I added the test case from your first patch and it passed. Funny thing is there seems to be a test already there for it anyway:
http://github.com/rails/rails/commit/95e1cf4812d4b964d7ab0fdf4bfa31...
-
Bogdan Gusiev
Hi Andrew,
That bug is truly fixed.
Seems there was more general change that fixed this bug in recent patches.I can´t reproduce it in Rails 3.0 but it is in 2.3.5.
So, you may close it at least for v3.0.Thanks,
Bogdan. -
Andrew White
- Milestone set to 2.3.10
- State changed from needs-more-info to open
-
Rohit Arondekar
- Tag changed from activerecord associations, activerecord, patch to activerecord, associations, patch
-
Jon Leighton
- Assigned user changed from Andrew White to Ryan Bigg
Reporter has indicated that this is no longer an issue in Rails 3, which is the current stable, so can this be closed please?
-
Jon Leighton
- State changed from open to resolved
