diff --git a/lib/src/sql/ident.rs b/lib/src/sql/ident.rs index 7f0d68d0..3100cdd3 100644 --- a/lib/src/sql/ident.rs +++ b/lib/src/sql/ident.rs @@ -48,6 +48,10 @@ impl Ident { pub fn to_raw(&self) -> String { self.0.to_string() } + /// Returns a yield if an alias is specified + pub(crate) fn is_id(&self) -> bool { + self.0.as_str() == "id" + } } impl Display for Ident { diff --git a/lib/src/sql/value/get.rs b/lib/src/sql/value/get.rs index 3ac67aa8..72e28800 100644 --- a/lib/src/sql/value/get.rs +++ b/lib/src/sql/value/get.rs @@ -4,10 +4,12 @@ use crate::dbs::Transaction; use crate::err::Error; use crate::sql::edges::Edges; use crate::sql::field::{Field, Fields}; +use crate::sql::id::Id; use crate::sql::part::Next; use crate::sql::part::Part; use crate::sql::paths::ID; use crate::sql::statements::select::SelectStatement; +use crate::sql::thing::Thing; use crate::sql::value::{Value, Values}; use async_recursion::async_recursion; use futures::future::try_join_all; @@ -27,6 +29,19 @@ impl Value { Some(p) => match self { // Current path part is an object Value::Object(v) => match p { + // If requesting an `id` field, check if it is a complex Record ID + Part::Field(f) if f.is_id() && path.len() > 1 => match v.get(f as &str) { + Some(Value::Thing(Thing { + id: Id::Object(v), + .. + })) => Value::Object(v.clone()).get(ctx, opt, txn, path.next()).await, + Some(Value::Thing(Thing { + id: Id::Array(v), + .. + })) => Value::Array(v.clone()).get(ctx, opt, txn, path.next()).await, + Some(v) => v.get(ctx, opt, txn, path.next()).await, + None => Ok(Value::None), + }, Part::Graph(_) => match v.rid() { Some(v) => Value::Thing(v).get(ctx, opt, txn, path).await, None => Ok(Value::None),