Giter Site home page Giter Site logo

Comments (5)

coreyk avatar coreyk commented on May 20, 2024

I guess if you do this it works:

def index(conn, params) do
  page =
    MyApp.Person
    |> where([p], p.age > 30)
    |> order_by(desc: :age)
    |> preload(:friends)
    |> MyApp.Repo.paginate(params)

  meow = %Scrivener.Page{entries: page.entries,
    page_number: page.page_number,
    page_size: page.page_size,
    total_pages: new_total_pages,
    total_entries: new_total_entries}

    render conn, :index, properties: meow

from scrivener_html.

mgwidmann avatar mgwidmann commented on May 20, 2024

Yes you could do that. However, I suppose this is more for the Scrivener project to tackle than here.
I'd just update the values rather than creating a new page...

render conn, :index, page: %{page | total_pages: new_total_pages, total_entries: new_total_entries}

But first, think about the fact that you're doing this before you do it. If the paginate function isnt giving you the data you want in those fields, ask yourself if maybe you're doing something wrong. I'd bet that @drewolson likely would want to know more about your use case in changing these values.

from scrivener_html.

coreyk avatar coreyk commented on May 20, 2024

The reason for this is to get around the limitation of Scrivener.Ecto when not selecting * and needing an accurate result count.

My queries are more complex than usual, with 6 joins, a where and a select on 10 columns across 7 tables. The count distinct can't be on *.

from scrivener_html.

mgwidmann avatar mgwidmann commented on May 20, 2024

either way, I'm not sure how this project should change to help you. You can already override the total_pages and total_entries like I showed, and then the helper function this project exposes will work just the same...

from scrivener_html.

drewolson avatar drewolson commented on May 20, 2024

@coreyk the newest release of scrivener_ecto uses subquery to produce accurate counts. Please take a look. This issue is unrelated to this project.

from scrivener_html.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.