Ensure edge in and out fields are not overwritten (#2506)

This commit is contained in:
Tobie Morgan Hitchcock 2023-08-24 09:19:19 +01:00 committed by GitHub
parent 1a4e310e46
commit a6ec9dbd02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -2,6 +2,7 @@ use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::dbs::Workable;
use crate::doc::Document;
use crate::err::Error;
use crate::sql::paths::EDGE;
@ -21,7 +22,13 @@ impl<'a> Document<'a> {
let rid = self.id.as_ref().unwrap();
// Set default field values
self.current.doc.to_mut().def(rid);
// Ensure edge fields are reset
// This is a RELATE statement, so reset fields
if let Workable::Relate(l, r) = &self.extras {
self.current.doc.to_mut().put(&*EDGE, Value::Bool(true));
self.current.doc.to_mut().put(&*IN, l.clone().into());
self.current.doc.to_mut().put(&*OUT, r.clone().into());
}
// This is an UPDATE of a graph edge, so reset fields
if self.initial.doc.pick(&*EDGE).is_true() {
self.current.doc.to_mut().put(&*EDGE, Value::Bool(true));
self.current.doc.to_mut().put(&*IN, self.initial.doc.pick(&*IN));

View file

@ -10,7 +10,7 @@ async fn relate_with_parameters() -> Result<(), Error> {
let sql = "
LET $tobie = person:tobie;
LET $jaime = person:jaime;
RELATE $tobie->knows->$jaime SET id = knows:test;
RELATE $tobie->knows->$jaime SET id = knows:test, brother = true;
";
let dbs = Datastore::new("memory").await?;
let ses = Session::owner().with_ns("test").with_db("test");
@ -32,6 +32,7 @@ async fn relate_with_parameters() -> Result<(), Error> {
id: knows:test,
in: person:tobie,
out: person:jaime,
brother: true,
}
]",
);
@ -45,7 +46,7 @@ async fn relate_and_overwrite() -> Result<(), Error> {
let sql = "
LET $tobie = person:tobie;
LET $jaime = person:jaime;
RELATE $tobie->knows->$jaime SET id = knows:test;
RELATE $tobie->knows->$jaime CONTENT { id: knows:test, brother: true };
UPDATE knows:test CONTENT { test: true };
SELECT * FROM knows:test;
";
@ -69,6 +70,7 @@ async fn relate_and_overwrite() -> Result<(), Error> {
id: knows:test,
in: person:tobie,
out: person:jaime,
brother: true,
}
]",
);