Process document fields correctly

This commit is contained in:
Tobie Morgan Hitchcock 2022-04-07 11:16:24 +01:00
parent e378105f11
commit 6b6d4f65f9

View file

@ -19,10 +19,12 @@ impl<'a> Document<'a> {
) -> Result<(), Error> { ) -> Result<(), Error> {
// Loop through all field statements // Loop through all field statements
for fd in self.fd(opt, txn).await?.iter() { for fd in self.fd(opt, txn).await?.iter() {
// Loop over each field in document
for k in self.current.each(&fd.name).into_iter() {
// Get the initial value // Get the initial value
let old = self.initial.get(ctx, opt, txn, &fd.name).await?; let old = self.initial.pick(&k);
// Get the current value // Get the current value
let mut val = self.current.get(ctx, opt, txn, &fd.name).await?; let mut val = self.current.pick(&k);
// Check for a VALUE clause // Check for a VALUE clause
if let Some(expr) = &fd.value { if let Some(expr) = &fd.value {
// Configure the context // Configure the context
@ -111,11 +113,12 @@ impl<'a> Document<'a> {
} }
// Set the value of the field // Set the value of the field
match val { match val {
Value::None => self.current.to_mut().del(ctx, opt, txn, &fd.name).await?, Value::None => self.current.to_mut().del(ctx, opt, txn, &k).await?,
Value::Void => self.current.to_mut().del(ctx, opt, txn, &fd.name).await?, Value::Void => self.current.to_mut().del(ctx, opt, txn, &k).await?,
_ => self.current.to_mut().set(ctx, opt, txn, &fd.name, val).await?, _ => self.current.to_mut().set(ctx, opt, txn, &k, val).await?,
}; };
} }
}
// Carry on // Carry on
Ok(()) Ok(())
} }