Add the rest of the relations

This commit is contained in:
Sam Samai 2021-06-29 19:57:05 +10:00
parent d103671701
commit c4fc1b1678
3 changed files with 31 additions and 0 deletions

View File

@ -38,6 +38,7 @@ impl PrimaryKeyTrait for PrimaryKey {
pub enum Relation {
Baker,
Order,
Cake,
}
impl ColumnTrait for Column {
@ -57,6 +58,7 @@ impl RelationTrait for Relation {
match self {
Self::Baker => Entity::has_many(super::baker::Entity).into(),
Self::Order => Entity::has_many(super::order::Entity).into(),
Self::Cake => Entity::has_many(super::cake::Entity).into(),
}
}
}
@ -67,4 +69,16 @@ impl Related<super::baker::Entity> for Entity {
}
}
impl Related<super::order::Entity> for Entity {
fn to() -> RelationDef {
Relation::Order.def()
}
}
impl Related<super::cake::Entity> for Entity {
fn to() -> RelationDef {
Relation::Cake.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -98,4 +98,10 @@ impl Related<super::baker::Entity> for Entity {
}
}
impl Related<super::lineitem::Entity> for Entity {
fn to() -> RelationDef {
Relation::Lineitem.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -39,6 +39,7 @@ impl PrimaryKeyTrait for PrimaryKey {
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
Order,
Cake,
}
impl ColumnTrait for Column {
@ -61,6 +62,10 @@ impl RelationTrait for Relation {
.from(Column::Id)
.to(super::order::Column::CustomerId)
.into(),
Self::Cake => Entity::belongs_to(super::cake::Entity)
.from(Column::Id)
.to(super::cake::Column::LineitemId)
.into(),
}
}
}
@ -71,4 +76,10 @@ impl Related<super::order::Entity> for Entity {
}
}
impl Related<super::cake::Entity> for Entity {
fn to() -> RelationDef {
Relation::Cake.def()
}
}
impl ActiveModelBehavior for ActiveModel {}