Fix validation on schemafull RELATE (#4226)

This commit is contained in:
Dmitrii Blaginin 2024-08-01 12:23:11 +01:00 committed by GitHub
parent 6935412c4b
commit e25ddfc408
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 2 deletions

View file

@ -37,10 +37,10 @@ impl<'a> Document<'a> {
opt: &Options,
stm: &Statement<'_>,
) -> Result<Value, Error> {
// Store record edges
self.edges(ctx, opt, stm).await?;
// Alter record data
self.alter(stk, ctx, opt, stm).await?;
// Store record edges
self.edges(ctx, opt, stm).await?;
// Merge fields data
self.field(stk, ctx, opt, stm).await?;
// Reset fields data

View file

@ -1,6 +1,9 @@
mod parse;
use parse::Parse;
mod helpers;
use crate::helpers::Test;
use helpers::new_ds;
use surrealdb::dbs::Session;
@ -207,3 +210,50 @@ async fn relate_with_complex_table() -> Result<(), Error> {
//
Ok(())
}
#[tokio::test]
async fn schemafull_relate() -> Result<(), Error> {
let sql = r#"
INSERT INTO person [
{ id: 1 },
{ id: 2 }
];
DEFINE TABLE likes TYPE RELATION FROM person TO person;
DEFINE FIELD reason ON likes TYPE string;
RELATE person:1 -> likes -> person:2 CONTENT {id: 1, reason: "nice smile"};
RELATE person:2 -> likes -> person:1 CONTENT {id: 2, reason: true};
RELATE dog:1 -> likes -> person:2 CONTENT {id: 3, reason: "nice smell"};
"#;
let mut t = Test::new(sql).await?;
t.expect_val(
"[
{id: person:1},
{id: person:2}
]",
)?;
t.skip_ok(2)?;
t.expect_val(
"[
{
id: likes:1,
in: person:1,
out: person:2,
reason: 'nice smile'
}
]",
)?;
// reason is bool not string
t.expect_error_func(|e| matches!(e, Error::FieldCheck { .. }))?;
// dog:1 is not a person
t.expect_error_func(|e| matches!(e, Error::FieldCheck { .. }))?;
Ok(())
}