Open
Description
Not 100% sure of where the issue is, but it seems to come up with has_many associations.
If I have a scope in a Foo model (where a user has_many: foos) - models/foo.rb:
belongs_to :user
scope :hasCars, -> { joins(:cars) }
And now try use the scope with will_paginate (in the controller):
@foos = auser.foos.hasCars.paginate(:page=>1,:per_page=>20)
Then the view duplicates each foo by the number of cars they have in the :through ownership association - so if auser.foos.first
has 3 cars. foos.first
will be iterated through 3 times in the paginated view.
I can work around this by using a group:
@foos = auser.foos.hasCars.group("car_id").paginate
http://stackoverflow.com/questions/11729816/rails-will-paginate-shows-duplicates-on-habtm-models
Metadata
Assignees
Labels
No labels