Forum

Thread tagged as: Question, Runway

Relations in perch_collection() filters

I would (very much) like to access Runway relations in the perch_collection() page function's filters.

<perch:related id="projectRelatedAddress" collection="Addresses" label="Related Address"></perch:related>

"Give me all projects with size 1 or who have some relation entered in the "Related Address" Field. And sort them by the street in the related address".

I tried this:

perch_collection('Items',[
   'template' => 'fe/project-teaser.html',
   // sort by a field of the relation
   'sort' => 'projectRelatedAddress.Street',
   'filter'=>array(
      // projects with size 1
      array(
         'filter'=>'projectSize',
         'match'=>'eq',
         'value'=>'1',
      ),
      // and who have ANY kind of relation in the field "projectRelatedAddress"
     // this is what I tried
      array(
         'filter'=>'projectRelatedAddress',
         'match'=>'neq',
         'value'=>'',
      ),
   ),
   'match'=>'or',
]);

But something seems to be wrong. How do I write that correctly?

Urs Bräm

Urs Bräm 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd use projectRelatedAddress.projectSize

Brilliant! Thaaaanks!!!