We get a lot of questions about relationships with multiple fields.
These extra fields give the relationship more context, like a date for example.
In such a case you’ll need a so-called “Link Table” to combine this into one relationship. This can be an extra Pod, table based or meta based.
Setup:
Assuming you’ve already setup the main/parent Pod and the Pod it relates to, you’ll need to create a third Pod, the LinkTable pod.
Call it anything you want but make sure it’s a bit explanatory as to what it stands for: the relationship.
Add all relationship context fields in this Pod, so this would be a relationship field to the child Pod and any other fields you need to add context to this relationship.
The parent Pod will only have a relationship field to this link table Pod.
You could add bi-directional relationship fields to all Pods if you want but this is optional.
Use cases:
1: Recipe ingredients
A recipe with multiple ingredients will need some context to those ingredients like the amount.
Main Pod: “recipe”
Child Pod: “ingredient”
Link Pod: “ingredient_amount”
The Link Pod “ingredient_amount” will only have two fields: “rel_ingredient”, the single relationship field to the ingredient Pod and “amount” for how much of this ingredient is needed.
The main Pod “recipe” has a multiple relationship field “rel_ingredient_amount” to the link Pod “ingredient_amount”.
Usage example 1: Pod Template
<ul> [each rel_ingredient_amount] <li>{@amount}: {@rel_ingredient.title}</li> [/each] </ul>
Usage example 2: PHP Template
<?php $pod = pods(); // Get current Pod. $ingredient_amount = $pod->field( 'rel_ingredient_amount', array('output'=>'find') ); ?> <ul> <?php while( $ingredient_amount->fetch() ) { ?> <li><?php echo $ingredient_amount->display( 'amount' ); ?>: <?php echo $ingredient_amount->display( 'rel_ingredient.title' ); ?></li> <?php } ?> </ul>