You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a scenario where the main table has a one-to-one relation with another table and also a one-to-many relation to the same table.
User - User details (1 to 1)
User -> Favourite profiles <-> User details (Many to many via favourite profiles)
Whenever I try to find the directly related User details (1-to-1) the query instead returns all the favourites eg
// Code is from memory so there might be a few differenceslet user = User::find_by_id(id).await?;let user_details = user.find_related(User_Details).await?;
I have looked at the docs but it only mentions how to create relations and not how to do an actual query using those relations. In the cases there are actual examples it is 1-to-many or many-to-many. It might be possible that I am using the wrong function or there is a different way around this. Admittedly,I could just call UserDetails.find_by_id(user.user_id).await but with all the examples for find_related it does give the impression that there is a function that does this that is generated by the macros or CLI.
Is there actually a function on the entity that would do this or is UserDetails.find_by_id(user.user_id).await the recommended way
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a scenario where the main table has a one-to-one relation with another table and also a one-to-many relation to the same table.
User - User details (1 to 1)
User -> Favourite profiles <-> User details (Many to many via favourite profiles)
Whenever I try to find the directly related User details (1-to-1) the query instead returns all the favourites eg
I have looked at the docs but it only mentions how to create relations and not how to do an actual query using those relations. In the cases there are actual examples it is 1-to-many or many-to-many. It might be possible that I am using the wrong function or there is a different way around this. Admittedly,I could just call
UserDetails.find_by_id(user.user_id).await
but with all the examples forfind_related
it does give the impression that there is a function that does this that is generated by the macros or CLI.Is there actually a function on the entity that would do this or is
UserDetails.find_by_id(user.user_id).await
the recommended wayBeta Was this translation helpful? Give feedback.
All reactions