Sort / Filter database records afterwards by a field in a foreign table

Crownpeak employee
Crownpeak employee
3 2 822

schemaIf you want to list all employees of a company ordered by name, you can sort the list later with the sort function.

The fr_comps Variable ist filled form a content select.

$CMS_FOR(company , fr_comps)$<ul>

          $CMS_FOR(employee , company.employeeList.sort(x -> x.surname))$
               <li>$CMS_VALUE(employee.surname)$, $CMS_VALUE(employee.firstname)$</li>

<CMS_FUNCTION name="contentSelect" resultname="fr_comps">
  <CMS_PARAM  name="schema" value="knowledgebase" />
  <QUERY entityType="company">

It is also possible to filter the list with the filter function.

$CMS_FOR(company , fr_comps)$
          $CMS_FOR(employee , company.employeeList.filter(x -> x.recruitmentdate > st_recruitmentdate))$
               <li>$CMS_VALUE(employee.surname)$, $CMS_VALUE(employee.firstname)$ ($CMS_VALUE($)</li>

The variable st_recruitmentdate is set by a formular (CMS_INPUT_DATE) where definend in a section template.

These feature were previously known as the lambda function, the old syntax (.sort(lambda(x : x.surname))) is marked as deprecated with the 4.1 release.

Version history
Last update:
‎06-30-2010 03:29 AM
Updated by: