This project is archived and is in readonly mode.
Association count with include doesn't alias join table
-
Bernardo Padua
IMO there are lots of discrepancies between count and find, this other one bugged be a lot: #348. They should be DRYed up.
-
Edvin Aghanian
- Tag set to activerecord, assertions, has_many, joins, tested
I've also run into this problem. I'm surprised this is not higher priority since the use of collections, etc, calls on count and immediately produces an error.
To work around this, I have simply been logging the object, which seems to allow the object set to be used as a collection in the view without calling 'count'.
-
Jeremy Kemper
- Milestone set to 2.1.1
- State changed from new to open
- Assigned user set to Jeremy Kemper
-
mech
This problem also occur at will_paginate when it uses count. For example:
@interviews = @job_posting.interviews.paginate(:include => :job_application)where the JobPosting class is as follow:
class JobPosting < AR has_many :job_applications has_many :interviews, :through => :job_applications end -
Tarmo Tänav
Possible fix for this (at least seems to satisfy the test and does actually cause the table to be aliased). Included the test from Ryan's patch as it didn't apply cleanly.
The basic problem was that JoinDependency was only aware of options[:joins] and not the tables that were joined throug scope(:find, :joins) so it didn't know the included association had to be aliased, my fix is simply to generate the full joins string earlier and pass that to JoinDependency. Tests pass, but in reality only around 15 tests hit that code branch and only two actually contain any joins.
-
Repository
- State changed from open to resolved
- Tag changed from activerecord, assertions, has_many, joins, tested to activerecord, assertions, has_many, joins, patch, tested
(from [0ed29df6fa704349fd0af0d9521581d6a8eb109c]) Alias included associations if needed when doing a count
[#302 state:resolved]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
James Le Cuirot
- Milestone cleared.
- Assigned user cleared.
- Importance changed from to
I know this ticket is really old but could you guys please take a look at ticket #3339 ? I have come up against a situation where tables are still being joined twice and a stronger solution is required. For count, it could mean removing this existing solution. I'd appreciate your comments.
