From 010c4e8cb8e455934e9a21a3e58cb79eff57b954 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Mon, 7 Jun 2021 19:25:37 +0800 Subject: [PATCH] Notes --- src/entity/active_model.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index e4374864..d6680ff5 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -198,7 +198,8 @@ where } } -/// Insert the model if primary key is unset, update otherwise +/// Insert the model if primary key is unset, update otherwise. +/// Only works if the entity has auto increment primary key. pub async fn save_active_model(mut am: A, db: &Database) -> Result where A: ActiveModelBehavior + ActiveModelTrait + From, @@ -229,6 +230,7 @@ where { let exec = E::insert(am).exec(db); let res = exec.await?; + // TODO: if the entity does not have auto increment primary key, then last_insert_id is a wrong value if res.last_insert_id != 0 { let find = E::find_by(res.last_insert_id).one(db); let res = find.await;