This question is similar to this one: Get attribute from touching line layer (QGIS) but there is a new and more komplex problem in that context I need to solve:
I have to plan drains, usually along a road network or any existing network digitized with snapping and tracing. In in that drains will be cables. The cables will also be digitized with tracing and end in every drain junction. No cables cross a junction. There could be up to 10 cables inside one drain. The drains are identified by ID's.
Every cable need a (virtual)field with the ID of the drain in which it lies. With the refFunctions solution:
(geomintersects('drain','drainid')
from the question linked above, I will get the drain ID for every cable, BUT the cables are also touching other drains at their end/start nodes if there is a junction. The results will become something like random! If the drains are not touching at their junctions (digitizing a small gab), the expression will work fine. But that is not a well suiting solution for me.
You can reproduce the situation with the following package: