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

Function insert_active_enum_child

tests/active_enum_tests.rs:267–345  ·  view source on GitHub ↗
(db: &DatabaseConnection)

Source from the content-addressed store, hash-verified

265}
266
267pub async fn insert_active_enum_child(db: &DatabaseConnection) -> Result<(), DbErr> {
268 use active_enum_child::*;
269
270 active_enum::ActiveModel {
271 category: Set(Some(Category::Small)),
272 color: Set(Some(Color::White)),
273 tea: Set(Some(Tea::BreakfastTea)),
274 ..Default::default()
275 }
276 .insert(db)
277 .await?;
278
279 let am = ActiveModel {
280 parent_id: Set(2),
281 category: Set(None),
282 color: Set(None),
283 tea: Set(None),
284 ..Default::default()
285 }
286 .insert(db)
287 .await?;
288
289 let model = Entity::find().one(db).await?.unwrap();
290 assert_eq!(
291 model,
292 Model {
293 id: 1,
294 parent_id: 2,
295 category: None,
296 color: None,
297 tea: None,
298 }
299 );
300 assert_eq!(
301 model,
302 Entity::find()
303 .filter(Column::Id.is_not_null())
304 .filter(Column::Category.is_null())
305 .filter(Column::Color.is_null())
306 .filter(Column::Tea.is_null())
307 .one(db)
308 .await?
309 .unwrap()
310 );
311
312 ActiveModel {
313 category: Set(Some(Category::Big)),
314 color: Set(Some(Color::Black)),
315 tea: Set(Some(Tea::EverydayTea)),
316 ..am.into_active_model()
317 }
318 .save(db)
319 .await?;
320
321 let model = Entity::find().one(db).await?.unwrap();
322 assert_eq!(
323 model,
324 Model {

Callers 1

mainFunction · 0.85

Calls 5

unwrapMethod · 0.80
saveMethod · 0.80
into_active_modelMethod · 0.80
insertMethod · 0.45
oneMethod · 0.45

Tested by

no test coverage detected