# Dynamic relationships

**URL:** <https://community.neo4j.com/t/dynamic-relationships/74077>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [June 6, 2025, 3:09pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077 "2025-06-06T15:09:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshcornejo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/joshcornejo/32/34171_2.png) [@joshcornejo](https://community.neo4j.com/u/joshcornejo)\
**Post date:** [June 6, 2025, 3:09pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/1 "2025-06-06T15:09:44Z")

</div>

Any idea why:

```auto
MATCH (A)-[:property]->(P)-[:type]->(T) 
MATCH (P)-[:value]->(V)
WITH A AS AU, V AS VU, T.code AS relName 
    CREATE (AU)-[:$(relName) {p:'1'}]->(VU)

```

... all the relationships created are the first node `(T)` found?

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [June 6, 2025, 10:49pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/2 "2025-06-06T22:49:56Z")

</div>

you got any sample data and the result that you can share?

---

<div class="post-metadata">

**Author:** ![joshcornejo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/joshcornejo/32/34171_2.png) [@joshcornejo](https://community.neo4j.com/u/joshcornejo)\
**Post date:** [June 7, 2025, 7:27am UTC](https://community.neo4j.com/t/dynamic-relationships/74077/3 "2025-06-07T07:27:03Z")

</div>

No data, but i think it is a bug ... If I do a return, I get a triples

```auto
MATCH (A)-[:property]->(P)-[:type]->(T) 
MATCH (P)-[:value]->(V)
WITH A.uuid AS AU, V.uuid AS VU, T.code AS relName 
RETURN AU, VU,relName

```

I ended up using the` apoc.text.join` to generate all the queries one by one:

```auto
MATCH (A) WHERE A.uuid='54:6b65977c-9dd8-4989-80f4-225b96258645:13244' MATCH (V) WHERE V.uuid ='1f51a86f-9389-498e-80b8-788da98a6857' WITH A, V CREATE (A)-[:size {p:1}]->(V);

```

`T.code = "size"` is the first node's property I need to use and the one ALL my relationships get in the origial query.

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [June 8, 2025, 2:36pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/4 "2025-06-08T14:36:02Z")

</div>

Do you have multiple paths between a given node A and node V? I assume each P has only one relationship to a node T.

Without seeing the data, I can't make an assessment of what is happening. I may look at refactoring the query to something like this, as you are really looking for the relationship between an A node and a V node, and you want to use the related T node to get the relationship type between a new path connecting A and V directly.

```auto
MATCH (A)-[:property]->(P)-[:value]->(V)
WITH A.uuid AS AU, V.uuid AS VU, [(P)-[:type]->(T)|T.code][0] AS relName 
RETURN AU, VU,relName

```

---

<div class="post-metadata">

**Author:** ![joshcornejo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/joshcornejo/32/34171_2.png) [@joshcornejo](https://community.neo4j.com/u/joshcornejo)\
**Post date:** [June 8, 2025, 2:40pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/5 "2025-06-08T14:40:15Z")

</div>

It looks like this:

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/1/e/1e1c6cac826ba50451105bd47aae75b75dc7ba9b.png)

---

<div class="post-metadata">

**Author:** ![joshcornejo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/joshcornejo/32/34171_2.png) [@joshcornejo](https://community.neo4j.com/u/joshcornejo)\
**Post date:** [June 8, 2025, 2:42pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/6 "2025-06-08T14:42:19Z")

</div>

And what i wanted:

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/e/9/e90da905a6f3370ec725e310f8832b4c3b74c6d7.png)

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [June 8, 2025, 4:14pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/7 "2025-06-08T16:14:22Z")

</div>

I created your scenario:

```auto
create(x0:Node{uuid:0,name:"A"}),(x1:Node{uuid:1, name:"P1"}),(x2:Node{uuid:2,name:"V1"}),(x3:Node{uuid:3,name:"V2"}),(x4:Node{uuid:4,name:"P2"}),(x5:Node{uuid:5,name:"T",type:"size"})
create(x0)-[:property]->(x1)-[:value]->(x2),(x1)-[:value]->(x3)
create(x0)-[:property]->(x4),(x1)-[:type]->(x5)

```

Result of my query:

```auto
MATCH (A)-[:property]->(P)-[:value]->(V)
WITH A, V, [(P)-[:type]->(T)|T.type][0] AS relName 
create(A)-[:$(relName)]->(V)

```

 ![Screenshot 2025-06-08 at 12.11.43 PM](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/4/6/46aa126703bf86dafc5b18ee7d6f18cfc9877ff0.png)

Result of your query:

```auto
MATCH (A)-[:property]->(P)-[:type]->(T) 
MATCH (P)-[:value]->(V)
create(A)-[:$(T.type)]->(V)

```

 ![Screenshot 2025-06-08 at 12.13.23 PM](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/4/c/4c14a9e7f86b856262e1521c5e791bbe25632783.png)

The results are the same and what I expected. I don't see an issue with your query with this isolated data set. Could there be some other property causing your issue with the "real" data?

---

<div class="post-metadata">

**Author:** ![joshcornejo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/joshcornejo/32/34171_2.png) [@joshcornejo](https://community.neo4j.com/u/joshcornejo)\
**Post date:** [June 8, 2025, 5:32pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/8 "2025-06-08T17:32:52Z")

</div>

I copy/pasted the query from when I did the find the issue (first query), nothing changed ... the label on the first relationship went to _ALL_ nodes A-[rel]-\>V, not just the first node, and not only to those that had the property.

Yet if i returned the triples, the label was different on each row.

---

<div class="post-metadata">

**Author:** ![rob.steward](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rob.steward/32/35104_2.png) [@rob.steward](https://community.neo4j.com/u/rob.steward)\
**Post date:** [June 9, 2025, 12:44pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/9 "2025-06-09T12:44:35Z")

</div>

Hi @joshcornejo

Do you know which version of Neo4j you are using? It's definitely possible you are running into a bug with Dynamic Types that was fixed in 5.26.4 LTS and 2025.03.

---

<div class="post-metadata">

**Author:** ![joshcornejo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/joshcornejo/32/34171_2.png) [@joshcornejo](https://community.neo4j.com/u/joshcornejo)\
**Post date:** [June 9, 2025, 2:13pm UTC](https://community.neo4j.com/t/dynamic-relationships/74077/10 "2025-06-09T14:13:27Z")

</div>

```auto
2025-03-13 07:40:24.583+0000 INFO ======== Neo4j 2025.02.0 ========

```

Will update!
