1

I'm trying to follow the approach shown in the introductory tutorial and building a page. The page is for a department and I've got a url like /department/12345, which Structr kindly automatically uses to look up the department node with the id 12345.

Then in the page I can use ${current.title}, or ${current.description}, but I'm not sure how to get at info about an entity that exists as an incoming/outgoing relationship. For instance, let's say I have a parent department that's named "parentDepartment" in the remote attributes section of the schema.

How do I display the parentDepartment's name on the page? I tried ${current.parentDepartment.name}, but that doesn't seem to be correct. I'd also like to know how and where to include the same sort of information for childDepartments, where there's potentially more than one child.

Daniel
  • 77
  • 7

2 Answers2

2

To use ${current.parentDepartment.name}, parentDepartment has to be an object and not a collection.

It seems that your data model is a tree, constructed with a simple self-relation of the type (:Department)-[:PARENT]->(:Department). It's important to set the cardinality right, so that the relation reads (:Department)-*-[:PARENT]-1->(:Department).

This way, the parent department attribute parentDepartment is a singular object and the childDepartments attribute (assuming that you renamed it) is a collection.

The display a collection's attributes, just use ${extract(childDepartments, 'name')}. To get a comma-separated list, just use ${join(extract(childDepartments, 'name'), ', ')}.

Axel Morgner
  • 2,292
  • 16
  • 15
  • Thanks again! I didn't know about the cardinality interface in the schema editor, so that's a huge help. I've got the parentDepartment working well now. I think I can use your advice about the childDepartments as well, although I'll need to look at the documentation to find a way to get out the objects so I can include their ids in the links I need to create as well. I'll write if I can't work it out. Once again, Structr finds a way to impress. – Daniel Oct 26 '16 at 13:51
1

Use a combination of incoming and find. Let the department node is of type Department:

${ each( incoming(page), 
         each( find('Department', 'id', data.sourceId), 
               print(data.name + '\r\n') 
         ) 
   ) 
 }
stdob--
  • 28,222
  • 5
  • 58
  • 73