MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / add

Method add

src/query/insert.rs:117–150  ·  view source on GitHub ↗
(mut self, m: M)

Source from the content-addressed store, hash-verified

115 /// Panics if the rows have different column sets from what've previously been cached in the query statement
116 #[allow(clippy::should_implement_trait)]
117 pub fn add<M>(mut self, m: M) -> Self
118 where
119 M: IntoActiveModel<A>,
120 {
121 let mut am: A = m.into_active_model();
122 self.primary_key =
123 if !<<A::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::auto_increment() {
124 am.get_primary_key_value()
125 } else {
126 None
127 };
128 let mut columns = Vec::new();
129 let mut values = Vec::new();
130 let columns_empty = self.columns.is_empty();
131 for (idx, col) in <A::Entity as EntityTrait>::Column::iter().enumerate() {
132 let av = am.take(col);
133 let av_has_val = av.is_set() || av.is_unchanged();
134 if columns_empty {
135 self.columns.push(av_has_val);
136 } else if self.columns[idx] != av_has_val {
137 panic!("columns mismatch");
138 }
139 match av {
140 ActiveValue::Set(value) | ActiveValue::Unchanged(value) => {
141 columns.push(col);
142 values.push(col.save_as(Expr::val(value)));
143 }
144 ActiveValue::NotSet => {}
145 }
146 }
147 self.query.columns(columns);
148 self.query.values_panic(values);
149 self
150 }
151
152 /// Add many Models to Self. This is the legacy implementation priori to `1.1.3`.
153 ///

Callers 15

prepare_conditionFunction · 0.80
find_also_linkedMethod · 0.80
find_with_linkedMethod · 0.80
oneMethod · 0.80
add_multiMethod · 0.80
join_tbl_on_conditionFunction · 0.80
apply_filterMethod · 0.80
build_with_queryFunction · 0.80
into_conditionMethod · 0.80
find_linkedFunction · 0.80
query_mysql_foreign_keysFunction · 0.80
routesFunction · 0.80

Calls 9

into_active_modelMethod · 0.80
get_primary_key_valueMethod · 0.80
takeMethod · 0.80
is_setMethod · 0.80
is_unchangedMethod · 0.80
pushMethod · 0.80
columnsMethod · 0.80
newFunction · 0.50
save_asMethod · 0.45

Tested by 1

build_with_queryFunction · 0.64