The Image above is the structure of a part of my graph database.
What I'm trying to achieve here is that I'm trying to search for product vertices by using the name of the of their related detail vertices.
The Expected output is a list of products with their details that has a name of test3
.
I am using choose step in my query to handle different values of my vertices.
g
.V()
.has('label',
within(
'data_computed_property',
'data_variable','recipe_ingredient',
'cost_setting_variable','benefit_analysis_variable',
'formula',
'detail'
)
)
.has('name', 'test3') // this is where i filter out all the detail vertices with a name of `test3`
.where(
__.in()
.has('label',
within(
'product',
'recipe',
'machine'
)
)
.in()
.has('id', '13eec000-78fa-41fd-856b-bbc37711b1f0')
)
.project('parent','property')
.by(
__.in()
.has('label',
within(
'product',
'recipe',
'machine'
)
)
.valueMap(true)
)
.by(
choose(values('label'))
.option(
'detail',
project('detail','value')
.by(valueMap(true))
.by(
choose(values('type'))
.option('string', values('value'))
.option('number', values('value'))
.option('date', values('value'))
.option('formula', out('value').valueMap(true))
.option('condition', out('value').valueMap(true))
.option('variable', out('value').valueMap(true))
.option('element', out('value').valueMap(true))
)
)
.option('data_computed_property', valueMap(true))
.option('data_variable', valueMap(true))
.option('recipe_ingredient', valueMap(true))
.option('cost_setting_variable', valueMap(true))
.option('benefit_analysis_variable', valueMap(true))
.option('formula', valueMap(true))
)
And this is the output of my query
array:2 [
0 => array:2 [
"parent" => array:3 [
"id" => "bee7eaa1-ad6c-436e-9000-7bf4665552d9"
"label" => "product"
"name" => array:1 [
0 => "Product 1"
]
"description" => array:1 [
0 => ""
]
"pk" => array:1 [
0 => "13eec000-78fa-41fd-856b-bbc37711b1f0"
]
"sku" => array:1 [
0 => "1235455"
]
]
"property" => array:2 [
"detail" => array:6 [
"id" => "5ad33864-25a7-424a-ba8d-a1b3e255d0a9"
"label" => "detail"
"name" => array:1 [
0 => "test3"
]
"type" => array:1 [
0 => "date"
]
"pk" => array:1 [
0 => "bee7eaa1-ad6c-436e-9000-7bf4665552d9/detail"
]
"value" => array:1 [
0 => 1583884800
]
]
"value" => 1583884800
]
]
1 => array:2 [
"parent" => array:3 [
"id" => "25c4cdfd-1845-4696-a427-5814d7adf71c"
"label" => "product"
"name" => array:1 [
0 => "Product 2"
]
"description" => array:1 [
0 => ""
]
"pk" => array:1 [
0 => "13eec000-78fa-41fd-856b-bbc37711b1f0"
]
"sku" => array:1 [
0 => "2569885"
]
]
"property" => array:2 [
"detail" => array:5 [
"id" => "db15ff37-4b13-4520-8e72-ae9f559f0fdc"
"label" => "detail"
"name" => array:1 [
0 => "test3"
]
"type" => array:1 [
0 => "variable"
]
"pk" => array:1 [
0 => "25c4cdfd-1845-4696-a427-5814d7adf71c/detail"
]
]
"value" => 1583884800
]
]
]
As you can see, the value
property for the last element of list is a value that belongs to the first item.
This is how the output is expected to look like
array:2 [
0 => array:2 [
"parent" => array:6 [
"id" => "bee7eaa1-ad6c-436e-9000-7bf4665552d9"
"label" => "product"
"name" => array:1 [
0 => "Product 1"
]
"description" => array:1 [
0 => ""
]
"pk" => array:1 [
0 => "13eec000-78fa-41fd-856b-bbc37711b1f0"
]
"sku" => array:1 [
0 => "1235455"
]
]
"property" => array:2 [
"detail" => array:6 [
"id" => "5ad33864-25a7-424a-ba8d-a1b3e255d0a9"
"label" => "detail"
"name" => array:1 [
0 => "test3"
]
"type" => array:1 [
0 => "date"
]
"pk" => array:1 [
0 => "bee7eaa1-ad6c-436e-9000-7bf4665552d9/detail"
]
"value" => array:1 [
0 => 1583884800
]
]
"value" => 1583884800
]
]
1 => array:2 [
"parent" => array:3 [
"id" => "25c4cdfd-1845-4696-a427-5814d7adf71c"
"label" => "product"
"name" => array:1 [
0 => "Product 2"
]
"description" => array:1 [
0 => ""
]
"pk" => array:1 [
0 => "13eec000-78fa-41fd-856b-bbc37711b1f0"
]
"sku" => array:1 [
0 => "2569885"
]
]
"property" => array:2 [
"detail" => array:5 [
"id" => "db15ff37-4b13-4520-8e72-ae9f559f0fdc"
"label" => "detail"
"name" => array:1 [
0 => "test3"
]
"type" => array:1 [
0 => "variable"
]
"pk" => array:1 [
0 => "25c4cdfd-1845-4696-a427-5814d7adf71c/detail"
]
]
"value" => [
"id" => "63b66993-cb5e-4cdb-b7c4-5db069106ac3"
"label" => "cost_setting_variable"
"name" => array:1 [
0 => "07/24/2021-variable"
]
"value" => array:1 [
0 => "50"
]
"pk" => array:1 [
0 => "4837194c-fe11-485a-9ef2-54fc0d621059"
]
]
]
]
]