diff --git a/Cargo.toml b/Cargo.toml
index 05b4332f6..6637a2309 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -34,7 +34,7 @@ tracing = { version = "0.1", default-features = false, features = ["attributes",
rust_decimal = { version = "1", default-features = false, optional = true }
bigdecimal = { version = "0.4", default-features = false, optional = true }
sea-orm-macros = { version = "~1.1.2", path = "sea-orm-macros", default-features = false, features = ["strum"] }
-sea-query = { version = "0.32.0", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
+sea-query = { version = "0.32.1", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.7.0", default-features = false, optional = true }
strum = { version = "0.26", default-features = false }
serde = { version = "1.0", default-features = false }
diff --git a/src/entity/base_entity.rs b/src/entity/base_entity.rs
index 5ed5d7572..0f534f531 100644
--- a/src/entity/base_entity.rs
+++ b/src/entity/base_entity.rs
@@ -467,6 +467,51 @@ pub trait EntityTrait: EntityName {
/// # Ok(())
/// # }
/// ```
+ ///
+ /// Before 1.1.3, if the active models have different column set, this method would panic.
+ /// Now, it'd attempt to fill in the missing columns with null
+ /// (which may or may not be correct, depending on whether the column is nullable):
+ ///
+ /// ```
+ /// use sea_orm::{
+ /// entity::*,
+ /// query::*,
+ /// tests_cfg::{cake, cake_filling},
+ /// DbBackend,
+ /// };
+ ///
+ /// assert_eq!(
+ /// cake::Entity::insert_many([
+ /// cake::ActiveModel {
+ /// id: NotSet,
+ /// name: Set("Apple Pie".to_owned()),
+ /// },
+ /// cake::ActiveModel {
+ /// id: NotSet,
+ /// name: Set("Orange Scone".to_owned()),
+ /// }
+ /// ])
+ /// .build(DbBackend::Postgres)
+ /// .to_string(),
+ /// r#"INSERT INTO "cake" ("name") VALUES ('Apple Pie'), ('Orange Scone')"#,
+ /// );
+ ///
+ /// assert_eq!(
+ /// cake_filling::Entity::insert_many([
+ /// cake_filling::ActiveModel {
+ /// cake_id: ActiveValue::set(2),
+ /// filling_id: ActiveValue::NotSet,
+ /// },
+ /// cake_filling::ActiveModel {
+ /// cake_id: ActiveValue::NotSet,
+ /// filling_id: ActiveValue::set(3),
+ /// }
+ /// ])
+ /// .build(DbBackend::Postgres)
+ /// .to_string(),
+ /// r#"INSERT INTO "cake_filling" ("cake_id", "filling_id") VALUES (2, NULL), (NULL, 3)"#,
+ /// );
+ /// ```
fn insert_many(models: I) -> Insert
where
A: ActiveModelTrait,
diff --git a/src/query/insert.rs b/src/query/insert.rs
index b13cd8a43..502f9a9fd 100644
--- a/src/query/insert.rs
+++ b/src/query/insert.rs
@@ -3,7 +3,7 @@ use crate::{
PrimaryKeyTrait, QueryTrait,
};
use core::marker::PhantomData;
-use sea_query::{Expr, InsertStatement, OnConflict, ValueTuple};
+use sea_query::{Expr, InsertStatement, Keyword, OnConflict, SimpleExpr, Value, ValueTuple};
/// Performs INSERT operations on a ActiveModel
#[derive(Debug)]
@@ -112,7 +112,7 @@ where
///
/// # Panics
///
- /// Panics if the column value has discrepancy across rows
+ /// Panics if the rows have different column sets from what've previously been cached in the query statement
#[allow(clippy::should_implement_trait)]
pub fn add(mut self, m: M) -> Self
where
@@ -149,15 +149,91 @@ where
self
}
+ /// Add many Models to Self. This is the legacy implementation priori to `1.1.3`.
+ ///
+ /// # Panics
+ ///
+ /// Panics if the rows have different column sets
+ #[deprecated(
+ since = "1.1.3",
+ note = "Please use [`Insert::add_many`] which does not panic"
+ )]
+ pub fn add_multi(mut self, models: I) -> Self
+ where
+ M: IntoActiveModel,
+ I: IntoIterator- ,
+ {
+ for model in models.into_iter() {
+ self = self.add(model);
+ }
+ self
+ }
+
/// Add many Models to Self
pub fn add_many(mut self, models: I) -> Self
where
M: IntoActiveModel,
I: IntoIterator
- ,
{
+ let mut columns: Vec<_> = ::Column::iter()
+ .map(|_| None)
+ .collect();
+ let mut null_value: Vec