Revert breaking changes
This commit is contained in:
parent
11208d627b
commit
19ec35f1b5
@ -92,7 +92,7 @@ pub trait ActiveModelTrait: Clone + Debug {
|
||||
}
|
||||
|
||||
async fn update(self, db: &DatabaseConnection) -> Result<Self, DbErr> {
|
||||
let exec = Self::Entity::update(self).prepare_filters().exec(db);
|
||||
let exec = Self::Entity::update(self).exec(db);
|
||||
exec.await
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@ impl Update {
|
||||
/// id: ActiveValue::set(1),
|
||||
/// name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
/// })
|
||||
/// .filter(cake::Column::Id.eq(1))
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"UPDATE "cake" SET "name" = 'Apple Pie' WHERE "cake"."id" = 1"#,
|
||||
@ -48,12 +47,13 @@ impl Update {
|
||||
E: EntityTrait,
|
||||
A: ActiveModelTrait<Entity = E>,
|
||||
{
|
||||
let myself = UpdateOne {
|
||||
let mut myself = UpdateOne {
|
||||
query: UpdateStatement::new()
|
||||
.table(A::Entity::default().table_ref())
|
||||
.to_owned(),
|
||||
model,
|
||||
};
|
||||
myself = myself.prepare_filters();
|
||||
myself.prepare_values()
|
||||
}
|
||||
|
||||
@ -86,19 +86,6 @@ impl<A> UpdateOne<A>
|
||||
where
|
||||
A: ActiveModelTrait,
|
||||
{
|
||||
pub(crate) fn prepare_values(mut self) -> Self {
|
||||
for col in <A::Entity as EntityTrait>::Column::iter() {
|
||||
if <A::Entity as EntityTrait>::PrimaryKey::from_column(col).is_some() {
|
||||
continue;
|
||||
}
|
||||
let av = self.model.get(col);
|
||||
if av.is_set() {
|
||||
self.query.value(col, av.unwrap());
|
||||
}
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn prepare_filters(mut self) -> Self {
|
||||
for key in <A::Entity as EntityTrait>::PrimaryKey::iter() {
|
||||
let col = key.into_column();
|
||||
@ -111,6 +98,19 @@ where
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn prepare_values(mut self) -> Self {
|
||||
for col in <A::Entity as EntityTrait>::Column::iter() {
|
||||
if <A::Entity as EntityTrait>::PrimaryKey::from_column(col).is_some() {
|
||||
continue;
|
||||
}
|
||||
let av = self.model.get(col);
|
||||
if av.is_set() {
|
||||
self.query.value(col, av.unwrap());
|
||||
}
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> QueryFilter for UpdateOne<A>
|
||||
@ -199,7 +199,6 @@ mod tests {
|
||||
id: ActiveValue::set(1),
|
||||
name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
})
|
||||
.filter(cake::Column::Id.eq(1))
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"UPDATE "cake" SET "name" = 'Apple Pie' WHERE "cake"."id" = 1"#,
|
||||
@ -214,7 +213,6 @@ mod tests {
|
||||
name: ActiveValue::set("Orange".to_owned()),
|
||||
cake_id: ActiveValue::unset(),
|
||||
})
|
||||
.filter(fruit::Column::Id.eq(1))
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"UPDATE "fruit" SET "name" = 'Orange' WHERE "fruit"."id" = 1"#,
|
||||
@ -229,7 +227,6 @@ mod tests {
|
||||
name: ActiveValue::unchanged("Apple".to_owned()),
|
||||
cake_id: ActiveValue::set(Some(3)),
|
||||
})
|
||||
.filter(fruit::Column::Id.eq(2))
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"UPDATE "fruit" SET "cake_id" = 3 WHERE "fruit"."id" = 2"#,
|
||||
|
Loading…
x
Reference in New Issue
Block a user