Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-27-2020 07:25 AM
Hello, everyone,
I have the following problem: I have modeled different bills of material, each with a different number of sub-items. Now my question is, I want to output the BOM with all items on the lowest level, I have already solved that, but I want to know all names of the corresponding upper assembly. So...
(Assembly)-[has]-(Assembly)-[has]-(Product)
(assembly)-[has]-(product)
Now each assembly sometimes has 2 and sometimes 3 or more sub-assemblies and in the last place always the product.
I would like to have the return:
subassembly | subassembly (if any)... | subassembly (if any)... | Product
Maybe someone can help me. Thank you very much.
Greetings
Julian
07-27-2020 12:43 PM
Are you looking to output a String consisting of subassemblies separated by |
characters with the Product as the last part of the string?
Or are you looking to output a fixed number of variables/columns with each corresponding to a subassembly (if it exists) with the Product as the last one? Or something else?
08-09-2020 09:24 PM
Hi,
yes i am looking for a String consisting of subassemblies separated by |
characters with the Product as the last part of the string.
08-24-2020 09:49 PM
This might get you started.
A variable-length relationship will provide the traversals needed through all subassemblies, ending in the product. If you have a path
variable, you can extract the nodes from the path. You can use apoc.text.join()
from APOC Procedures to join up the values with |
symbols between them.
So assuming the name
property is desired for output, and is present on both assemblies and the product, maybe something like this:
MATCH path = (start:Assembly)-[:has*]->(:Product)
WHERE NOT ()-[:has]->(start) // ensure start is the start of the chain, not in the middle
AND all(node in nodes(path)[..-1] WHERE node:Assembly) // for all nodes except the last
RETURN apoc.text.join([node in nodes(path) | node.name], ' | ') as output
08-09-2020 11:33 PM
Hello @julian-hartmann
We will need more details to write a query but I can give you some tips to make your query:
Regards,
Cobra
All the sessions of the conference are now available online