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

Suprising interaction between BoxedExperssions, Subselects and BoxedSelectStatements #1544

Open
weiznich opened this Issue Feb 6, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@weiznich
Contributor

weiznich commented Feb 6, 2018

Setup

Versions

  • Rust: rustc 1.25.0-nightly (0c6091fbd 2018-02-04)
  • Diesel: 20e92c5
  • Database: not relevant (Sqlite)
  • Operating System not relevant (Ubuntu)

Feature Flags

  • diesel: features = ["r2d2", "sqlite", "chrono"]

Problem Description

I'm trying to dynamically construct some queries containing eventually some subselect statements. I reduced my problem to the code below.

What are you trying to accomplish?

use diesel::*;
use diesel::sql_types::Bool;

table! {
    heros {
        id -> Integer,
        name -> Text,
        species -> Integer,
        home_world -> Nullable<Integer>,
    }
}

table! {
    species {
        id -> Integer,
        name -> Text,
    }
}

fn test() {
    let my_condition = Box::new(species::id.eq(1)) as Box<BoxableExpression<species::table, Sqlite, SqlType = Bool>>;
    let subselect = species::table.filter(my_condition).select(species::id);

    let my_condition = Box::new(heros::species.eq_any(subselect));

    let query = heros::table.into_boxed::<Sqlite>().filter(my_condition);
}

What is the expected output?

The code compiles.
The strange thing about this is the following:

  • Removing the into_boxed() while constructing the query makes the code compile
  • Also removing the filter (but not the select !) call while constructing the subselect makes it compile

At least this behavior seems to be quite surprising for me. I would expect at leas that the second point is not possible or that this query is possible.

What is the actual output?

This error was emitted.

Are you seeing any additional errors?

No

Checklist

  • I have already looked over the issue tracker for similar issues.
@sgrif

This comment has been minimized.

Member

sgrif commented Feb 6, 2018

You'll need to change the first parameter of BoxableExpression to Join<left::table, right::table, Inner>

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