diff --git a/src/query/insert.rs b/src/query/insert.rs index 6c5e55b2c..1d50329c2 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -225,6 +225,21 @@ where { TryInsert::from_insert(self) } + + /// On conflict do nothing + pub fn on_conflict_do_nothing(mut self) -> TryInsert + where + A: ActiveModelTrait, + { + let primary_keys = ::PrimaryKey::iter(); + self.query.on_conflict( + OnConflict::columns(primary_keys.clone()) + .do_nothing_on(primary_keys) + .to_owned(), + ); + + TryInsert::from_insert(self) + } } impl QueryTrait for Insert @@ -319,13 +334,6 @@ where // helper function for do_nothing in Insert pub fn from_insert(mut insert: Insert) -> Self { - let primary_keys = ::PrimaryKey::iter(); - insert.query.on_conflict( - OnConflict::columns(primary_keys.clone()) - .do_nothing_on(primary_keys) - .to_owned(), - ); - Self { insert_struct: insert, } diff --git a/tests/empty_insert_tests.rs b/tests/empty_insert_tests.rs index b4123d54f..e902a4fac 100644 --- a/tests/empty_insert_tests.rs +++ b/tests/empty_insert_tests.rs @@ -41,7 +41,7 @@ pub async fn test(db: &DbConn) { }; let conflict_insert = Bakery::insert_many([double_seaside_bakery]) - .on_empty_do_nothing() + .on_conflict_do_nothing() .exec(db) .await;