How do I use a join table? #2768
-
|
Hi sorry but I cant find any documentation or examples on how to achieve this: My schema is: Now, given a I've tried variations around: But I get compile error: Would it be possible to document how to achieve this or point me towards those docs if they already exist? Many thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
A left join makes all columns coming from the joined table As another semi-related note: You don't need to join 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 at our documentation it seems like we should also mention this in the documentation of |
Beta Was this translation helpful? Give feedback.
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::tablein this case, as this table is not used anywhere in your query.A fixed version of your example would look like:
From looking …