Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special ForeignModel and BackRef for one-to-one relations #71

Open
gammelalf opened this issue Jul 26, 2024 · 0 comments
Open

Special ForeignModel and BackRef for one-to-one relations #71

gammelalf opened this issue Jul 26, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@gammelalf
Copy link
Member

#[derive(Model)]
struct Data {
    #[rorm(id)]
    id: i64,
    
    extras: BackRef<field!(Extra::F.data)>,
}

#[derive(Model)]
struct Extra {
    #[rorm(id)]
    id: i64,
    
    data: ForeignModel<Data>,
}

This is a classic many-to-one relation.

By adding #[rorm(unique)] to data: ForeignModel<Data>, you turn it into a one-to-one relation.
(technically "one-to-optional" would be more fitting, because a Data could still have zero Extra, but not more than one).

However the BackRef on Data doesn't take not of this change. I'd like some specialized version of BackRef which only connects to #[rorm(unique)] ForeignModels to provide extra semantics and methods.

@gammelalf gammelalf added the enhancement New feature or request label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant