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

Compile failed with pagination (code in example) #1505

Closed
sackery opened this Issue Jan 23, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@sackery

sackery commented Jan 23, 2018

use schema::{node, users};
impl Node {
    ...
    pub fn load_many_with_user(current_page: i64, conn: &PgConnection) -> QueryResult<(Vec<(Node, String)>, i64)> {
        use schema::node::dsl::*;

        node.filter(status.ne(-1))
            .order(created.desc())
            .inner_join(users::table)
            .select((node::all_columns, users::name))
            .paginate(current_page)
            .per_page(PAGER_PAGE_LIMIT)
            .load_and_count_pages::<(Node, String)>(conn)
    }
    ...
}

The errors:

error[E0277]: the trait bound `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}: diesel::expression::NonAggregate` is not satisfied
  --> src/models/node.rs:72:14
   |
72 |             .select((node::all_columns, users::name))
   |              ^^^^^^ the trait `diesel::expression::NonAggregate` is not implemented for `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)`
   = note: required because of the requirements on the impl of `diesel::query_dsl::select_dsl::SelectDsl<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>` for `diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::DefaultSelectClause, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>`

error[E0277]: the trait bound `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}: diesel::SelectableExpression<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>>` is not satisfied
  --> src/models/node.rs:72:14
   |
72 |             .select((node::all_columns, users::name))
   |              ^^^^^^ the trait `diesel::SelectableExpression<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>>` is not implemented for `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}`
   |
   = note: required because of the requirements on the impl of `diesel::SelectableExpression<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>>` for `(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)`
   = note: required because of the requirements on the impl of `diesel::query_builder::select_clause::SelectClauseExpression<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>>` for `diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>`
   = note: required because of the requirements on the impl of `diesel::Expression` for `diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>`
   = note: required because of the requirements on the impl of `diesel::query_dsl::select_dsl::SelectDsl<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>` for `diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::DefaultSelectClause, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>`

error[E0277]: the trait bound `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}: diesel::expression::NonAggregate` is not satisfied
  --> src/models/node.rs:75:14
   |
75 |             .load_and_count_pages::<(Node, String)>(conn)
   |              ^^^^^^^^^^^^^^^^^^^^ the trait `diesel::expression::NonAggregate` is not implemented for `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)`
   = note: required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<diesel::PgConnection, ((models::node::Node, std::string::String), i64)>` for `sandech::utils::dbutils::pager::Paginated<diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>>`

error[E0277]: the trait bound `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}: diesel::SelectableExpression<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>>` is not satisfied
  --> src/models/node.rs:75:14
   |
75 |             .load_and_count_pages::<(Node, String)>(conn)
   |              ^^^^^^^^^^^^^^^^^^^^ the trait `diesel::SelectableExpression<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>>` is not implemented for `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}`
   |
   = note: required because of the requirements on the impl of `diesel::SelectableExpression<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>>` for `(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)`
   = note: required because of the requirements on the impl of `diesel::query_builder::select_clause::SelectClauseExpression<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>>` for `diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>`
   = note: required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<diesel::PgConnection, ((models::node::Node, std::string::String), i64)>` for `sandech::utils::dbutils::pager::Paginated<diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>>`

error[E0277]: the trait bound `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}: diesel::query_builder::QueryFragment<diesel::pg::Pg>` is not satisfied
  --> src/models/node.rs:75:14
   |
75 |             .load_and_count_pages::<(Node, String)>(conn)
   |              ^^^^^^^^^^^^^^^^^^^^ the trait `diesel::query_builder::QueryFragment<diesel::pg::Pg>` is not implemented for `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}`
   |
   = note: required because of the requirements on the impl of `diesel::query_builder::QueryFragment<diesel::pg::Pg>` for `(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)`
   = note: required because of the requirements on the impl of `diesel::query_builder::select_clause::SelectClauseQueryFragment<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::pg::Pg>` for `diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>`
   = note: required because of the requirements on the impl of `diesel::query_builder::QueryFragment<diesel::pg::Pg>` for `diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>`
   = note: required because of the requirements on the impl of `diesel::query_builder::QueryFragment<diesel::pg::Pg>` for `sandech::utils::dbutils::pager::Paginated<diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>>`
   = note: required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<diesel::PgConnection, ((models::node::Node, std::string::String), i64)>` for `sandech::utils::dbutils::pager::Paginated<diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>>`

error[E0277]: the trait bound `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}: diesel::query_builder::QueryId` is not satisfied
  --> src/models/node.rs:75:14
   |
75 |             .load_and_count_pages::<(Node, String)>(conn)
   |              ^^^^^^^^^^^^^^^^^^^^ the trait `diesel::query_builder::QueryId` is not implemented for `fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}`
   |
   = note: required because of the requirements on the impl of `diesel::query_builder::QueryId` for `(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)`
   = note: required because of the requirements on the impl of `diesel::query_builder::QueryId` for `diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>`
   = note: required because of the requirements on the impl of `diesel::query_builder::QueryId` for `diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>`
   = note: required because of the requirements on the impl of `diesel::query_builder::QueryId` for `sandech::utils::dbutils::pager::Paginated<diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>>`
   = note: required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<diesel::PgConnection, ((models::node::Node, std::string::String), i64)>` for `sandech::utils::dbutils::pager::Paginated<diesel::query_builder::SelectStatement<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::node::table, schema::users::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::node::columns::user_id>, diesel::expression::nullable::Nullable<schema::users::columns::id>>>, diesel::query_builder::select_clause::SelectClause<(fn() -> <schema::node::table as diesel::Table>::AllColumns {<schema::node::table as diesel::Table>::all_columns}, schema::users::columns::name)>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::NotEq<schema::node::columns::status, diesel::expression::bound::Bound<diesel::sql_types::SmallInt, i16>>>, diesel::query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<schema::node::columns::created>>>>`

error: aborting due to 6 previous errors
@weiznich

This comment has been minimized.

Contributor

weiznich commented Jan 23, 2018

The problem is the following line:

 use schema::node::dsl::*;

This imports a type alias for node::table named node, which causes this error message. Changing node::all_columns into ::schema::node::all_columns should fix your problem.

@sgrif

This comment has been minimized.

Member

sgrif commented Jan 23, 2018

You can also change node::all_columns to node::all_columns() if you have node::dsl::* in scope.

@sgrif sgrif closed this Jan 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment