Forum

Thread tagged as: Question, Runway

Reverse relationships

Here's my church template:

<perch:categories id="area" set="areas-geographical" label="Area" required="true" />
<perch:content id="parish_name" type="text" label="Parish Name" title="true" />
<perch:categories id="borough" set="boroughs" label="Borough" required="true" />
<perch:content id="location" type="map" label="Location" />
<perch:content id="church_size" type="text" label="Church Size" />
<perch:content id="status" type="select" label="Status" options="Active|active,Archived|archived" default="Active" />
<perch:content id="church_slug" type="brd_slug" for="parish_name" collection="Churches" editable="true" label="Church slug" />

And here's the project template (which lets you choose a related church).

<perch:related id="church" collection="Churches" label="Parish">
    <perch:content id="parish_name" title="true"  />    
</perch:related>
<perch:content id="description" type="text" label="Description/Project name" title="true"  />
<perch:categories id="activity_type" set="activity-type" label="Activity Type" required="true" />
<perch:categories id="area_of_concern" set="area-of-concern" label="Area of concern" required="true" />
<perch:content id="beneficiaries" type="text" label="Beneficiaries" />
<perch:content id="volunteers" type="text" label="Volunteers" />
<perch:content id="notes" type="text" label="Notes" />
<perch:content id="status" type="select" label="Status" options="Active|active,Archived|archived" default="Active" />
<perch:content id="project_slug" type="brd_slug" for="description" collection="Projects" editable="true" label="Project Slug" />

I can display a project (list or single project) and show the related church.

What I haven't worked out how to do is to display a "church" detail page and show all the projects related to that church. (The church is related to the project by the field in the projects template). Is this possible? What should my template look like?

<div class="row">
    <div class="col-md-12">
        <h1 class="main-heading"><perch:content id="parish_name" title="true"  /></h1>
    </div>
</div>
<div class="main-content">
<div class="row">
    <div class="col-md-4 col-md-push-2">
    <dl class="dl-horizontal">
        <dt>Parish</dt>
        <dd><perch:content id="parish_name" title="true"  /></dd>
        <dt>Borough</dt>
        <dd>
            <perch:categories id="borough" set="boroughs" label="Borough" required="true">
                <perch:category id="catTitle" type="smarttext" label="Title" required="true" />
            </perch:categories>
        </dd>
        <dt>Area</dt>
        <dd>
            <perch:categories id="area" set="areas-geographical" label="Area"  required="true">
                <perch:category id="catTitle" type="smarttext" label="Title" required="true" />
            </perch:categories>
        </dd>
    </dl>
    </div>
    <div class="col-md-4 col-md-push-2">
        <perch:content id="location" type="map" />
    </div>
</div>
<div class="row">
    RELATED PROJECTS GO HERE
</div>
</div>
Paul Bell

Paul Bell 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to filter:

perch_collection('Projects', [
    'filter' => 'church._id',
    'value' => $your_current_church_id,
]);