Return Vec<Option<Type>
with belonging_to
#4402
-
Hello, I have an optional 1-to-1 relation set up between let extra_info: Option<ExtraSongInfo> = ExtraSongInfo::belonging_to(&song)
.first(&mut conn)
.await
.optional()?; Now, I want to do this for a let extra_info = ExtraSongInfo::belonging_to(&songs)
.select(ExtraSongInfo::as_select())
.load(&mut conn)
.await
.optional()?; This, however, returns How can I actually get |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The correct way to model an 1:1 relation is using a join. For optional 1:1 dependencies that means you want to use In this particular case you end up with a query like that: songs::table.left_join(extra_song_info::table).filter(songs::id.eq_any(song_ids)).select(Option::<ExtraSongInfo>::as_select()).load(&mut conn)?; See the Relation Guide for more details and information on this topic.
That's an issue in rust-analyzer, not in diesel. Please report it in their issue tracker, as we cannot do much about it. |
Beta Was this translation helpful? Give feedback.
-
That works, thank you! |
Beta Was this translation helpful? Give feedback.
The correct way to model an 1:1 relation is using a join. For optional 1:1 dependencies that means you want to use
left_join()
.In this particular case you end up with a query like that:
See the Relation Guide for more details and information on this topic.
That's an issue in rust-analyzer, not in diesel. Please report it in their issue tracker, as we cannot do much about it.