Search the Community
Showing results for tags 'database relation'.
-
Conditioning Database Relation fields
Jimi Wikman posted an invision community guide in Invision Community Pages Basic relationship
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"} {{endforeach}} <!-- end the queries --> {{endif}} {{endforeach}} {{endif}} 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.-
- database relation
- custom fields
-
(and 1 more)
Tagged with: