Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Very Popular

    Conditioning Database Relation fields

    Jimi Wikman
    Message added by Jimi Wikman,

    I am working on an update on this article since there are more than one scenario and I want to add some illustrations as well.

    In order to condition a custom field of the type Database Relation, you need to have a different query. This is because the normal check uses the processed output, which for Database Relation fields will always be true.  So what we do instead is use this code:

    {{if $records = $record->getReciprocalItems()}}
    {{foreach $records as $fieldId => $items}}
    {{if $fieldId == 'ID of the field you want to check'}}
    <!-- Parsing out the fields using a template -->
    {{foreach $items as $item}}
    {template="BasicRelationship_template" app="cms" group="basic_relationship_templates" params="$item"}      
    <!-- end the queries -->

    In the first part, we first put a condition that if the database the template is used on have "reciprocal items", meaning if you have incoming links from other databases. Then we loop through the incoming items and select only the ones that match the ID of the field that is pointing towards the current database.

    So, if you for example have a database called Movies and one database called Actors where Movies have a database relation to Actors. Movies have Database ID 1 and Actors have database ID 2. The Custom field in the Movies database have the Field ID 100. We would then add the $fieldId == '100' into our code. Anytime we look at a Movie in the Movies database, we will trigger this condition and we will show the actors related to this movie.

    This will, however, NOT trigger if you are looking at an actor in the Actor database. This is because the condition will look only at links from outside databases. If you want to link to another database item in the same database, like linking actor to another actor, then you will instead use the standard condition for custom fields to do so.

    Discuss the Guide

    Recommended Comments

    There are no comments to display.

    Please sign in to comment

    You will be able to leave a comment after signing in

    Sign In Now

  • Latest Updates

  • Create New...