Orientdb fetch relationship as array in json -


i want fetch vertices connected edge returned array property in json.

eg: if post has 10 comments query should return this.

{     @class: post,     posttitle: "some title",     comments: [         {             @class: comment,            content: "first comment,            somekey: "some value"           },         {             @class: comment,            content: "second comment            somekey: "some value"         }     ] } 

it possible 1 property of vertices in array query

select *, out('has_comment').content comments post 

this result in array has value of 'content' property in comment class

i need fetch full record nested json.

update

if use out('has_comment') in query instead of out('has_comment').content , returns @rid field instead of full record.

i tried case structure :

create class post extends v create class comment extends v create class has_comment extends e  create property post.posttitle string create property comment.content string create property comment.somekey integer  create vertex post set posttitle="first" create vertex post set posttitle="second" create vertex comment set content="first comment", somekey="1" create vertex comment set content="second comment", somekey="2" create vertex comment set content="third comment", somekey="3" create vertex comment set content="fourth comment", somekey="4" create vertex comment set content="fifth comment", somekey="5" create vertex comment set content="sixth comment", somekey="6" create vertex comment set content="seventh comment", somekey="7" create vertex comment set content="eighth comment", somekey="8" create vertex comment set content="ninth comment", somekey="9" create vertex comment set content="tenth comment", somekey="10" create vertex comment set content="eleventh comment", somekey="11" create vertex comment set content="twelfth comment", somekey="12" create vertex comment set content="thirteenth comment", somekey="13" create vertex comment set content="fourteenth comment", somekey="14"  create edge has_comment (select post posttitle="first") (select comment content="first comment") create edge has_comment (select post posttitle="first") (select comment content="second comment") create edge has_comment (select post posttitle="first") (select comment content="third comment") create edge has_comment (select post posttitle="first") (select comment content="fourth comment") create edge has_comment (select post posttitle="first") (select comment content="fifth comment") create edge has_comment (select post posttitle="first") (select comment content="sixth comment") create edge has_comment (select post posttitle="first") (select comment content="seventh comment") create edge has_comment (select post posttitle="first") (select comment content="eighth comment") create edge has_comment (select post posttitle="first") (select comment content="ninth comment") create edge has_comment (select post posttitle="first") (select comment content="tenth comment") create edge has_comment (select post posttitle="second") (select comment content="eleventh comment") create edge has_comment (select post posttitle="second") (select comment content="twelfth comment") create edge has_comment (select post posttitle="second") (select comment content="thirteenth comment") create edge has_comment (select post posttitle="second") (select comment content="fourteenth comment") 

to result want, can use following query:

select expand($ris)     let $a = (select post posttitle = 'first'),         $b = (select comment in('has_comment').posttitle in $a.posttitle),         $ris = unionall($a,$b) 

studio:

enter image description here

console output:

----+-----+-------+---------+---------------+---------------+-------+-------------- #   |@rid |@class |posttitle|out_has_comment|content        |somekey|in_has_comment ----+-----+-------+---------+---------------+---------------+-------+-------------- 0   |#12:0|post   |first    |[size=10]      |null           |null   |null 1   |#13:0|comment|null     |null           |first comment  |1      |[size=1] 2   |#13:1|comment|null     |null           |second comment |2      |[size=1] 3   |#13:2|comment|null     |null           |third comment  |3      |[size=1] 4   |#13:3|comment|null     |null           |fourth comment |4      |[size=1] 5   |#13:4|comment|null     |null           |fifth comment  |5      |[size=1] 6   |#13:5|comment|null     |null           |sixth comment  |6      |[size=1] 7   |#13:6|comment|null     |null           |seventh comment|7      |[size=1] 8   |#13:7|comment|null     |null           |eighth comment |8      |[size=1] 9   |#13:8|comment|null     |null           |ninth comment  |9      |[size=1] 10  |#13:9|comment|null     |null           |tenth comment  |10     |[size=1] ----+-----+-------+---------+---------------+---------------+-------+-------------- 

about question underlined in update, full record/s @rid can use expand() function.

example:

getting of comments connected vertex post posttitle = 'second'

query: select expand(out('has_comment')) post posttitle = 'second'

studio:

enter image description here

console output:

----+------+-------+------------------+-------+-------------- #   |@rid  |@class |content           |somekey|in_has_comment ----+------+-------+------------------+-------+-------------- 0   |#13:10|comment|eleventh comment  |11     |[size=1] 1   |#13:11|comment|twelfth comment   |12     |[size=1] 2   |#13:12|comment|thirteenth comment|13     |[size=1] 3   |#13:13|comment|fourteenth comment|14     |[size=1] ----+------+-------+------------------+-------+-------------- 

hope helps

edited

query:

select *, $a comments post let $a = (select @class, content, somekey comment in('has_comment').posttitle in $parent.current.posttitle) 

studio:

enter image description here


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -