Already created relationship does not persist for future nodes

Hi All,

I'm with years of RDMS experience. Started exploring Neo4j and stuck on one scenario, I'm sure I am doing something wrong but I do not know what. Your help in clearing my confusion will be greatly appreciated.

Code in the order of execution

CREATE (:Schema {SchemaID:3, SchemaCode:'CRM', SchemaName:'Customer Management'})

CREATE (:Table {TableID:52, TableName:'Customer', SchemaID:3})

MATCH (a:Schema), (b:Table)
WHERE a.SchemaID = b.SchemaID
CREATE (a)-[:OWNS]->(b)

MATCH (c:Schema where c.SchemaCode = 'CRM') RETURN c

This far everything is good. I can see CRM node and if click 'relationship' symbol it shows me Customer table.

And now execute this code (basically add another node)

CREATE (:Table {TableID:57, TableName:'Address', SchemaID:3})

MATCH (c:Schema where c.SchemaCode = 'CRM') return c

Now here is problem. I can see CRM node but when expand for relationship it is still showing Customer table i.e. Address node is missing from the relationship. Remember Address node is added after the relationship was created.

Any idea why relations is missing for future nodes after it has been created?

BTW if I run MERGE for relationship after new node then I can see the new node in the relationship. I hope we do not have to execute merge relationship after every new node creation.

Thanks in advance

Shahzad

Houston TX.

Neo4j is not like a relational database that relates rows in two tables with keys. Although you could simulate this with equal keys in different entities and join with a match whose predicate specifies the keys are equal, this is typically not done in a graph database. It doesn’t leverage the benefits of a graph database. Instead, relationships are created between entities that makes it easy and quick to find related entities. These links are built into the data. They are not derived each query through a join.

I think this misunderstanding may be the root of your issues. Adding a new entity with a key value equal to another entity with a key with the same value dies not relate them. You need to create a relationship between each pair of nodes where they are needed.

your lines 5 and 6 are like an inner join in sql. You would not use this approach to derive the relationship between these nodes each time, but create the relationship as you do in line 7 and the use the relationship to find one of the nodes given the other node.

it’s a different way of thinking. You still have primary keys to uniquely identify entities for finding nodes, but you use relationships instead of foreign keys.

does thus help?

Thanks a lot for the reply.

This is my weekend learning project so please give me some time to digest what you wrote.

Do you think if I go thru the Movie example that will help me to change my thinking from RDBMS to Graph way?

I suggest a few free neo4j courses:

Manual Reading:

Experimenting:

@glilienfield Thank you so mush for your time and consideration. I will look your suggested course and re-consider my design.

Again thanks for being patience with the novice.

Thanks,

Shahzad.