I want to fetch the vertices connected by the edge to be returned as an array as a property in json.
Eg: If a POST has 10 comments the query should return something like this.
{
@class: Post,
postTitle: "Some title",
comments: [
{
@class: Comment,
content: "First Comment,
someKey: "Some Value"
},
{
@class: Comment,
content: "Second Comment
someKey: "Some Value"
}
]
}
It is possible to get one property of the vertices in an array by this query
select *, out('HAS_COMMENT').content as comments from POST
This will result in an array which has only the value of 'content' property in the Comment class
I need to fetch the full record as a nested json.
UPDATE
If I just use out('HAS_COMMENT')
in the query instead of out('HAS_COMMENT').content
, it returns the @rid
field instead of full record.
I tried your case with this structure :
To get the result you want, you can use the following query:
Studio:
Console output:
About your question underlined in your UPDATE, to get the full record/s from the
@rid
you can use theexpand()
function.Example:
Getting all of the comments connected with the vertex Post where
postTitle = 'Second'
Query:
select expand(out('HAS_COMMENT')) from Post where postTitle = 'Second'
Studio:
Console output:
Hope it helps
EDITED
Query:
Studio: