If the query you want to paginate already contains a :limit or an :offset clause, you may get wrong results because you would override these clauses when applying pagination. The solution is to use a sub-query. You need to modify execute_query like this:
defpexecute_query(query,page)doquery|>maybe_wrap_in_subquery()|>limit(^@results_per_page)|>offset((^page-1)*^@results_per_page)|>Repo.all()end# no :limit/:offset, so no need to wrap the original query in a subquerydefpmaybe_wrap_in_subquery(%{limit:nil,offset:nil}=query),do:querydefpmaybe_wrap_in_subquery(query),do:subquery(query)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If the query you want to paginate already contains a
:limit
or an:offset
clause, you may get wrong results because you would override these clauses when applying pagination. The solution is to use a sub-query. You need to modifyexecute_query
like this: