-
-
Notifications
You must be signed in to change notification settings - Fork 521
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
Codegen Handle Self Referencing & Multiple Relations to the Same Related Entity #347
Conversation
…ns to the same related entity
I took a quick read through the code, but not a deep dive yet. I'll try doing some exports on my databases when I get time, and see what comes up. Super excited to see this! |
Do let us know the test results :P |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I did not author codegen
. Way more complicated than I thought. Seems cool enough though.
Alright, I loaded in my database, and it seems to Here is a model with two fields that reference a wallet (some code was removed): //! SeaORM Entity. Generated by sea-orm-codegen 0.4.0
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "currencies_transaction")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub amount: Option<i32>,
pub from_wallet_id: Option<i64>,
pub to_wallet_id: Option<i64>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::currencies_wallet::Entity",
from = "Column::FromWalletId",
to = "super::currencies_wallet::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
CurrenciesWallet2,
#[sea_orm(
belongs_to = "super::currencies_wallet::Entity",
from = "Column::ToWalletId",
to = "super::currencies_wallet::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
CurrenciesWallet1,
}
impl Related<super::currencies_trade_transactions::Entity> for Entity {
fn to() -> RelationDef {
Relation::CurrenciesTradeTransactions.def()
}
}
impl ActiveModelBehavior for ActiveModel {} |
Nice!! |
PR Info