Skip to content

How do I use a join table? #2768

Answered by weiznich
felixwatts asked this question in Q&A
Discussion options

You must be logged in to vote

A left join makes all columns coming from the joined table Nullable. Diesel expresses this by requiring you to call .nullable() on the corresponding fields in your select clause. See this documentation for examples.

As another semi-related note: You don't need to join beds::table in this case, as this table is not used anywhere in your query.

A fixed version of your example would look like:

    let notes = bed_notes::table
        .left_join(notes::table)
        .filter(bed_notes::bed_id.eq(id))
        .select((notes::dsl::id.nullable(), notes::dsl::time.nullable(), notes::dsl::text.nullable()))
        .load::<Note>(&connection)
        .expect("Error loading bed notes");

From looking …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@felixwatts
Comment options

Answer selected by weiznich
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants