doctrinesymfony-cmfdoctrine-phpcr

Doctrine PHPCR @Children & @Child


I started learning PHPCR with doctrine in Symfony-CMF, and I have a question. Is that possible to have @Children and @Child on 2 differents attributes of the same document ?

According to the doc...

The annotated instance variable will be populated with Documents directly below the instance variables document class in the document hierarchy.

I think that there should be only one @Children or @Child per document. But how to manage forms if there's different documents into the same attribute ? It's not clear for me the usage of this. Should I choose one attribute whith @Children & @ReferenceOne / @ReferenceMany on the others ?


Solution

  • PHPCR is a tree, every node is located under its parent. For the parent, that is a child node. When using @Child, you adress one specific child with a field. Using @Children, you map all child documents and the member variable having this mapping contains a collection. note that there is a middle ground: you can specify to filter @Children by a naming pattern of the children.

    indeed you can end up with the same child in @Child and @Children - we recommend to not inline the editing of an unfiltered children collection, but make that links. if you have a filtered children collection and a separate child, things can work out nicely.

    references are cross-links not following the tree hierarchy. they are less efficient than parent-child relations. you should only use those for secondary relations, but keep your primary content structured in the tree.