-
-
Notifications
You must be signed in to change notification settings - Fork 661
Closed
Description
Motivation
Ive integrated sea orm in a quite complex project where the need arises for computed columns from different tables.
Proposed Solutions
A potential solution could be to have a computed column annotated on the model (which is not included in the derived active model) and just link a function which gets called on every selection of the model:
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)]
#[sea_orm(table_name = "invoice_line_item")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
#[sea_orm(foreign_key)]
pub invoice_id: i64,
// ..
pub amount: i64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)]
#[sea_orm(table_name = "invoice")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
#[sea_orm(compute = "Entity::total")]
pub total: i64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl Entity {
async fn total(pk: i64) -> Result<i64, sea_orm::error::DbErr> {
// Run query which sums all related invoice line items
}
}Additional Information
I think this would be pretty useful to a lot of realworld applications, what do you think about this? 🙂
ippsav, itsbalamurali, KevSlashNull, borrow-checker, UkonnRa and 1 more
Metadata
Metadata
Assignees
Labels
No labels