I’m struggling with a complex query that I am trying to paginate.
Basically I have two tables: Tasks and WorkEntries. A Task has_many
WorkEntries and each task belongs_to a User. Basically I want to
display recent work entries for the current user so I want to do
something like:
select we., task. from work_entries we where we.task.user_id =
#{current_user.id}
Now if I do this:
@entry_pages, @entries = paginate :work_entry, { :per_page => 20,
:conditions => ["tasks.user_id = ? and work_entries.stop_at is not
This eager loads the task but the pagination count is wrong because
there is no join for model.count() to take into account so I get the
cross-product of both tables.
If I try to do both, I get invalid SQL due to the tasks table being
joined twice. Is there a way to get this to work correctly?