Ensure edge in
and out
fields are not overwritten (#2506)
This commit is contained in:
parent
1a4e310e46
commit
a6ec9dbd02
2 changed files with 12 additions and 3 deletions
|
@ -2,6 +2,7 @@ use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
|
use crate::dbs::Workable;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::paths::EDGE;
|
use crate::sql::paths::EDGE;
|
||||||
|
@ -21,7 +22,13 @@ impl<'a> Document<'a> {
|
||||||
let rid = self.id.as_ref().unwrap();
|
let rid = self.id.as_ref().unwrap();
|
||||||
// Set default field values
|
// Set default field values
|
||||||
self.current.doc.to_mut().def(rid);
|
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() {
|
if self.initial.doc.pick(&*EDGE).is_true() {
|
||||||
self.current.doc.to_mut().put(&*EDGE, Value::Bool(true));
|
self.current.doc.to_mut().put(&*EDGE, Value::Bool(true));
|
||||||
self.current.doc.to_mut().put(&*IN, self.initial.doc.pick(&*IN));
|
self.current.doc.to_mut().put(&*IN, self.initial.doc.pick(&*IN));
|
||||||
|
|
|
@ -10,7 +10,7 @@ async fn relate_with_parameters() -> Result<(), Error> {
|
||||||
let sql = "
|
let sql = "
|
||||||
LET $tobie = person:tobie;
|
LET $tobie = person:tobie;
|
||||||
LET $jaime = person:jaime;
|
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 dbs = Datastore::new("memory").await?;
|
||||||
let ses = Session::owner().with_ns("test").with_db("test");
|
let ses = Session::owner().with_ns("test").with_db("test");
|
||||||
|
@ -32,6 +32,7 @@ async fn relate_with_parameters() -> Result<(), Error> {
|
||||||
id: knows:test,
|
id: knows:test,
|
||||||
in: person:tobie,
|
in: person:tobie,
|
||||||
out: person:jaime,
|
out: person:jaime,
|
||||||
|
brother: true,
|
||||||
}
|
}
|
||||||
]",
|
]",
|
||||||
);
|
);
|
||||||
|
@ -45,7 +46,7 @@ async fn relate_and_overwrite() -> Result<(), Error> {
|
||||||
let sql = "
|
let sql = "
|
||||||
LET $tobie = person:tobie;
|
LET $tobie = person:tobie;
|
||||||
LET $jaime = person:jaime;
|
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 };
|
UPDATE knows:test CONTENT { test: true };
|
||||||
SELECT * FROM knows:test;
|
SELECT * FROM knows:test;
|
||||||
";
|
";
|
||||||
|
@ -69,6 +70,7 @@ async fn relate_and_overwrite() -> Result<(), Error> {
|
||||||
id: knows:test,
|
id: knows:test,
|
||||||
in: person:tobie,
|
in: person:tobie,
|
||||||
out: person:jaime,
|
out: person:jaime,
|
||||||
|
brother: true,
|
||||||
}
|
}
|
||||||
]",
|
]",
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue