Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I found an error of document on the official guides page. #66

Open
leehyong opened this issue Jul 6, 2018 · 0 comments
Open

I found an error of document on the official guides page. #66

leehyong opened this issue Jul 6, 2018 · 0 comments

Comments

@leehyong
Copy link

leehyong commented Jul 6, 2018

Problem Description

On official guides the page Using Custom SQL and How to Extend the Query DSL, I found an error of document. See the following:

impl<T> Paginated<T> {
    fn load_and_count_pages<U>(self, conn: &PgConnection) -> QueryResult<(Vec<U>, i64)
    where
        Self: LoadQuery<PgConnection, (U, i64)>,
    {
        let per_page = self.per_page;
        let results = self.load::<(U, i64)>(conn)?;
        let total = results.get(0).map(|(_, total) _total|).unwrap_or(0);
        let records = results.into_iter().map(|(record, _)| record).collect();
        let total_pages = (total as f64 / per_page as f64).ceil() as i64;
        Ok((records, total_pages))
    }
}

The seventh line of the sample code above should be:

 let total = results.get(0).map(|(_, total)| _total).unwrap_or(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant