2

My templates that referenced entry.children or entry.getChildren() have started throwing deprecation notices:

Calling getChildren() to fetch an element’s target relations has been deprecated. Use the relatedTo param instead.

What is the preferred way to search for an entry's children — either ALL of its children, or just its direct children — using the relatedTo() param?

  • What type of entries are these? You should not get these messages for structure entries (see BaseElementModel, line 540). – carlcs Dec 4 '14 at 7:57
  • Good catch, @carlcs. My use case is in generating some nav links. (There are a few edge cases where my entry may not be a structure entry, in which case it has no children and generates no nav options...) – Michael Rog Dec 4 '14 at 14:03
5

It appears the preferred way is by using getDescendants() — In fact, the children property is actually an alias for getDescendants(1). (The parameter specifies a maximum distance (i.e. number of levels) of the child from the parent.)

  • Yes, you should use getDescendants. But the error came because you applied getChildren to the wrong type of elements (getChildren was replaced with relatedTo for these type of relations at some point). – carlcs Dec 4 '14 at 14:12
  • Just found it in the Craft 1.3.2409 release notes. – carlcs Dec 4 '14 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.