I have two tables that I want to retrieve values from using a LEFT JOIN
. Diesel wants to handle any values from the joined table as nullable (which is sensible, given that there may or may not be a record), and it surfaces this in Rust using Option<T>
.
I want my struct to contain a T
, and if the corresponding record is absent, use T::default()
. So, essentially, I just want the final type to get an .unwrap_or_default
at the end.
In other words, instead of…
struct MyStuff {
left_table_data: String,
right_table_data: Option<String>,
}
I want…
struct MyStuff {
left_table_data: String,
#[diesel(deserialize_as = Option<String>, ...)] // something to make diesel call `unwrap_or_default`
right_table_data: String,
}
Is there a way to do this within the Diesel API, without manually coding an intermediate struct or similar?