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

pack order into BoxableExpression #3412

Closed
weiznich opened this issue Nov 15, 2022 Discussed in #3411 · 0 comments
Closed

pack order into BoxableExpression #3412

weiznich opened this issue Nov 15, 2022 Discussed in #3411 · 0 comments

Comments

@weiznich
Copy link
Member

Discussed in #3411

Originally posted by mlesin November 15, 2022
I'm following documentation of BoxableExpression trait, trying to pack dynamically chosen order into BoxableExpression:

    let order_field: Box<dyn BoxableExpression<tasks::table, Pg, SqlType = NotSelectable>> =
        match order.field {
            TasksOrderField::Id => {
                if order.ascending {
                    Box::new(tasks::id.asc())
                } else {
                    Box::new(tasks::id.desc())
                }
            }
            TasksOrderField::Label => {
                if order.ascending {
                    Box::new(tasks::label.asc())
                } else {
                    Box::new(tasks::label.desc())
                }
            }
        };
    query = query.order(order_field);

But this is fails to compile with the following message:

   |
74 |     query = query.order(order_field);
   |                   ^^^^^ the trait `AppearsOnTable<FromClause<tasks::table>>` is not implemented for `dyn BoxableExpression<tasks::table, Pg, SqlType = NotSelectable>`

And I have no idea how to satisfy AppearsOnTable<FromClause<..>> trait because FromClause trait is private.
What am I doing wrong?

Guara92 pushed a commit to Guara92/diesel that referenced this issue Nov 23, 2022
This commits fixes an issue that disallowed the usage of
`BoxableExpression` as order clause due to a malformed trait impl in diesel.
Guara92 pushed a commit to Guara92/diesel that referenced this issue Nov 23, 2022
This commits fixes an issue that disallowed the usage of
`BoxableExpression` as order clause due to a malformed trait impl in diesel.
weiznich added a commit that referenced this issue Nov 24, 2022
weiznich added a commit to weiznich/diesel that referenced this issue Jan 18, 2023
This commits fixes an issue that disallowed the usage of
`BoxableExpression` as order clause due to a malformed trait impl in diesel.
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