Question about complex(?) relationships #450
Replies: 10 comments 1 reply
-
Hey @videobitva, you could use |
Beta Was this translation helpful? Give feedback.
-
Thank you, I tried to look into that. As far as I could understood |
Beta Was this translation helpful? Give feedback.
-
Correct! |
Beta Was this translation helpful? Give feedback.
-
Ok, so my question remains the same: how (or can I even) define both UPD: I think I got it, will try to implement it and write it down here if got (or not) any success |
Beta Was this translation helpful? Give feedback.
-
No, I still don't get it. In order to make relations between impl Related<super::switch_port::Entity> for Entity {
fn to() -> RelationDef {
Relation::SwitchPort.def()
}
} but I can't, because in order to do that I need to properly implement this: impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::SwitchPort => Entity::belongs_to(super::switch_port::Entity)...
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Use Linked trait with https://docs.rs/sea-orm/0.4.2/sea_orm/?search=_linked find_linked methods |
Beta Was this translation helpful? Give feedback.
-
And you can move this code into the Linked def()
|
Beta Was this translation helpful? Give feedback.
-
Sorry, gonna sleep now. Let's continue the conversation tmr loll |
Beta Was this translation helpful? Give feedback.
-
Thank you, have a good sleep =) |
Beta Was this translation helpful? Give feedback.
-
I see Here is the link definition for port 2, you can do the same with port 1 or use the relation (enum) #[derive(Debug)]
pub struct SwitchPortTwo;
impl Linked for SwitchPortTwo {
type FromEntity = Entity;
type ToEntity = super::switch_port::Entity;
fn link(&self) -> Vec<RelationDef> {
vec![
Entity::belongs_to(super::switch_port::Entity)
.from((Column::SwitchIdTwo, Column::PortIdTwo))
.to((super::switch_port::Column::SwitchId, super::switch_port::Column::PortId))
.into(),
]
}
} |
Beta Was this translation helpful? Give feedback.
-
Hello there!
I have been struggling to implement this kind of relationship:
Here is the code which I came up with:
The problem is that if implementing it this way only relationships
switch_id_two -> switch_id
andport_id_two -> port_id
are built.So my question is: how can I make this work?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions