How to display relationship types?

If I display related entities by:
<unit relativeTo="ca_entities.related" delimiter="<br/>"><l>^ca_entities.related.preferred_labels.displayname</l></unit>

how do I include the relationship type?

<unit relativeTo="ca_entities.related" delimiter="<br/>"><l>^relationship_type_id  ^ca_entities.related.preferred_labels.displayname</l></unit> doesn't work

«1

Comments

  • The special tags are

    ^relationship_typename
    ^relationship_type_id
    ^relationship_typecode

    I think they must be in the context of the relationship though, outside the unit tag.
  • I cant get anyone of them to return anything in or out of the <unit> block.

  • Just tried it out ... works like a charm?

    These tags are only available in relationship context though. So if you're running the template against a record like an object you might have to switch context to the relationship table first .. e.g.:

    <unit relativeTo="ca_objects_x_entities">^relationship_typename</unit>

    For relationship bundles the context should be the relationship, so just plugging in the tag should work. But I don't know where you're trying to do this.
  • I should point out that this is in Pawtucket2.
    I'm trying to list related entities to an entity and the relationship type.
    I started with the default ca_entities_default_html.php.  I want to include a list of related entities (that is already part of the default) but I want to also include the relationship type.
    It seems like maybe <unit relativeTo="ca_entities_x_entities">^relationship_typename</unit> is what I would want...but it doesn't work.

  • edited August 2015
    Self-relationships are a little tricky in that you sometimes have to tell the template processor which side you're evaluating from.

    I just added a few relatively simple tests that run some ca_entities_x_entities cases:

    https://github.com/collectiveaccess/providence/blob/master-fix/tests/testsWithData/get/EntitiesXEntitiesTest.php#L106

    These tests all pass, so I think the template processor works ok. Note that when I try to pull ca_entities.preferred_labels from the relationship record, I have to tell it which side to use to resolve links (the $va_opts variable).
  • I am still stuck,  I can get the related entities's idno, description, entity type_id, etc just fine.  I CAN NOT GET THE RELATIONSHIP TYPE!

    I would like to list related entities and their types as "parent of" and "child of".  I do not know if this is because I am dealing with pawtaucket2 and not providence that it will not work?
  • edited August 2015
    Possible, but unlikely. The template processor code should be the same, although Pawtucket2 is usually a bit behind. This is not a new feature though.

    It would help if you showed us what exactly you tried! Did you take a look at the tests I linked in the previous post?
  • - I started with the default themes/default/views/Details/ca_entities_default_html.php  and copied it to my theme: themes/pelhamhs2/views/Details/ca_entities_default_html.php

    - I then changed the lines: {{{<unit relativeTo="ca_entities" delimiter="<br/>"><l>^ca_entities.related.preferred_labels.displayname</l></unit>}}}
    to: {{{<unit relativeTo="ca_entities.related" delimiter="<br/>"><l>^ca_entities.preferred_labels.displayname (^relationship_typename)</l></unit>}}} to allow the links to work correctly (otherwise they link to the current record and not the related entity)

    -It seems like any combination of <unit relativeTo="ca_entities_x_entities"> will not return anything either within the unit: <unit relativeTo="ca_entities" delimiter="<br/>"><unit relativeTo="ca_entities_x_entities">^relationship_typename</unit></unit> or outside ie: <unit relativeTo="ca_entities_x_entities">^relationship_typename</unit>


    I tried to play around with the tests...but I am not too sure how to get them to actually run (I'm on a shared server without shell access)  I tried to pull the test apart and use it as am example within the detail page...but I couldn't get anything usefull to happen.

    Bruce
  • Hmm, the templates look okay I guess. No idea what's going on ...
  • Hi Bruce,

    If you really can't get this to work, you might try with php.  Something like:

    <?php

    if ($va_entities = $t_item->get('ca_entities', array('template' => ' <unit relativeTo="ca_entities_x_occurrences"><unit relativeTo="ca_entities"><l>^ca_entities.preferred_labels</l></unit> (^relationship_typename)</unit>', 'delimiter' => '<br/>'))) {
    print "<div class='unit'><H6>Related Entities</h6>".$va_entities."</div>";
    }

    ?>
  • So this is as far as I have been able to get:

    if ($va_entities = $t_item->get('ca_entities', array('template' => '
                                <unit relativeTo="ca_entities.related">
                                    <l>^ca_entities.preferred_labels</l>
                                    <unit relativeTo="ca_entities_x_entities">
                                        ( ^relationship_typename )                             
                                    </unit>
                                </unit>
                            ', 'delimiter' => '<br/>')))
                            {
                                print "<div class='unit'><H6>Related Entities</h6>".$va_entities."</div>";
                        }


    The problem is that this ALWAYS displays the foward relationship...even when it should be the reverse relationship.  It displays OK in Providence so I know the relationships are correct.

  • What version of Pawtucket are you using? I realize that you've probably already answered this question but I haven't been paying attention lately (sorry)

    The template parser recently got a rewrite, so the first step for me in figuring out the issue is to know which implementation you're using.

    thanks
    seth
  • running from git/develop pawtucket2 pulled this morning.


  • What is the $t_item? An entity?
  • yes.  The code was kind of pulled from various examples, so I guess I should rename my variables.
    When I examine an entity in Providence then I see the related entities with the correct relationships:
    ie: If Joe is Parent of Sam, then Sam will display as Child to Joe
     (where the relationship parent_child is setup as Parent as the forward relationship and Child as the reverse)

  • Try this:

    print $t_item->getWithTemplate('
                                    <l>^ca_entities.related.preferred_labels</l>
                                    <unit relativeTo="ca_entities_x_entities"> 
                                        ( ^relationship_typename )                              
                                    </unit>
                            ', array('delimiter' => '<br/>'));

    What does that give you?
  • nope...still just displays the forward relationships.
  • Would you be able to share your data and theme with me so I can try to reproduce this?
  • 7 years later, I am having a similar issue as Bruce in displaying the right typename in Pawtucket2

    With entities I created a relationship structure that I thought would allow to show a basic family.

    In entities <> entities I created a relationship type code, "paternal" that in Providence works well. The typename forward is "child of" and reverse is "father of"

    So Philip Levy is the father of Priscilla Levy.

    In Providence, for the "paternal" relationship, from Philip I can set the typename as "father of" from his side, or from Priscilla I can set this typename as "child of" and then it shows the meaningful typename from either entity.

    The problem is that in Pawtucket when doing something like this it always shows the forward sense

    <ifcount code="ca_entities.related"><label>Family</label></ifcount>}}}  

      {{{<unit relativeTo="ca_entities_x_entities" restrictToRelationshipTypes="paternal" delimiter="<br/>"><l>^ca_entities.related.preferred_labels.displayname</l> (^relationship_typename)</unit>

    So for Philip's record it is showing Priscilla but the typename is displayed as "child of" when it should be "father of"

    I tried the php snippets given above as well, but like for Bruce, it still always displays the forward sense

  • This should have been fixed a while back. What version of Pawtucket are you running?

  • Pawtucket2, 1.7.9, last pull was March 2021. I also tried ca_relationship_types.preferred_labels.typename but it still always shows the forward type

  • I'm having the same issue, no clue as how to display the typename of a relationship in a Detail page in Pawtucket.

  • What does the template you're using look like?

  • {{{<if rule="^ca_objects.work_type =~ /foto|gráf/">

        <ifcount code="ca_objects_x_objects" restrictToRelationshipTypes="part_of" min="1">

        <tr>

            <td><?php print _t("Part of"); ?></td>

            <td>

            <unit relativeTo="ca_objects_x_objects" restrictToRelationshipTypes="part_of" delimiter=" ">

                <unit relativeTo="ca_objects" delimiter=" ">

                    <l>^ca_objects.preferred_labels</l>

                    <ifdef code="ca_objects.work_type">

                        (^ca_objects.work_type.preferred_labels%useSingular&makeFirstUpper)

                    </ifdef>

                    <br/>

                </unit>

            </unit>

            </td>

        </tr>

        </ifcount>

    </if>}}}

  • Have you tried ^relationship_typename ?

  • ^relationship_typename is the tag you want, and it must be in the <unit> relative to the relationship table. See below, which works on the demo system as expected.

    <ifcount code="ca_objects_x_objects" restrictToRelationshipTypes="part_of" min="1">
      <tr>
        <td><?php print _t("Part of"); ?></td>
        <td>
        <unit relativeTo="ca_objects_x_objects" restrictToRelationshipTypes="part_of" delimiter=" ">
          <unit relativeTo="ca_objects" delimiter=" ">
            <l>^ca_objects.preferred_labels</l>
            <ifdef code="ca_objects.work_type">
              (^ca_objects.work_type.preferred_labels%useSingular&makeFirstUpper) 
            </ifdef>
            <br/>
          </unit> (^relationship_typename)
        </unit>
        </td>
      </tr>
      </ifcount>
    
  • edited May 20

    It is not displaying the relationship, just the parenthesis.

    The version is 1.7.7, maybe this is the problem?

    This is the code:

    {{{<if rule="^ca_objects.work_type =~ /foto|gráf/">
        <ifcount code="ca_objects_x_objects" restrictToRelationshipTypes="part_of" min="1">
      <tr>
        <td><?php print _t("Part of"); ?></td>
        <td>
        <unit relativeTo="ca_objects_x_objects" restrictToRelationshipTypes="part_of" delimiter=" ">
          <unit relativeTo="ca_objects" delimiter=" ">
            <l>^ca_objects.preferred_labels</l>
            <ifdef code="ca_objects.work_type">
              (^ca_objects.work_type.preferred_labels%useSingular&makeFirstUpper) 
            </ifdef>
            <br/>
          </unit> (^relationship_typename)
        </unit>
        </td>
      </tr>
      </ifcount>
    </if>}}}
    


  • Yes, that is the problem.

  • edited June 2

    Hi mbutel,

    I have the same problem with Pawtucket 1.7.6: no way to display ^relationship_typename for an object linked with another object (or an entity linked with another entity, or a place related to another place...).

    But, the relationship typename can be used to restrict display of elements. So what I made to solve (until an updated version...) this problem is:


                {{{<unit relativeTo="ca_objects.related" delimiter=" " restrictToRelationshipTypes="related">
                <l>^ca_objects.preferred_labels</l> (is related to)<br/></unit>}}}
                {{{<unit relativeTo="ca_objects.related" delimiter=" " restrictToRelationshipTypes="duplicate">
                <l>^ca_objects.preferred_labels</l> (is a duplicate of)<br/></unit>}}}
                {{{<unit relativeTo="ca_objects.related" delimiter=" " restrictToRelationshipTypes="showviewof">
                <l>^ca_objects.preferred_labels</l> (contains a view of)<br/></unit>}}}
                {{{<unit relativeTo="ca_objects.related" delimiter=" " restrictToRelationshipTypes="same_author">
                <l>^ca_objects.preferred_labels</l> (has same author)<br/></unit>}}}
                {{{<unit relativeTo="ca_objects.related" delimiter=" " restrictToRelationshipTypes="used_for_manufacture_of">
                <l>^ca_objects.preferred_labels</l> (is used for manufacture of)<br/></unit>}}}
                {{{<unit relativeTo="ca_objects.related" delimiter=" " restrictToRelationshipTypes="source">
                <l>^ca_objects.preferred_labels</l> (is source of)<br/></unit>}}}
                {{{<unit relativeTo="ca_objects.related" delimiter=" " restrictToRelationshipTypes="part_of">
                <l>^ca_objects.preferred_labels</l> (is a part of)</unit>}}}
    

    Example for places:

                   {{{<unit relativeTo="ca_places.related" delimiter=" " restrictToRelationshipTypes="related">
                   <l>^ca_places.preferred_labels.name</l> (is related to)<br/></unit>}}}
                   {{{<unit relativeTo="ca_places.related" delimiter=" " restrictToRelationshipTypes="connected-to">
                   <^ca_places.preferred_labels.name</l> (is connected to)<br/></unit>}}}
                   {{{<unit relativeTo="ca_places.related" delimiter=" " restrictToRelationshipTypes="is-a-part-of">
                   <l>^ca_places.preferred_labels.name</l> (is a part of)<br/></unit>}}}
    

    Example for entities:

    {{{<unit relativeTo="ca_entities.related" delimiter=" " restrictToTypes="ind" restrictToRelationshipTypes="related">
     <l>^ca_entities.preferred_labels.displayname</l> (is related to)<br/></unit>}}}
     {{{<unit relativeTo="ca_entities.related" delimiter=" " restrictToTypes="ind" restrictToRelationshipTypes="succeeded">
     <l>^ca_entities.preferred_labels.displayname</l> (succeeded to)<br/></unit>}}}
     {{{<unit relativeTo="ca_entities.related" delimiter=" " restrictToTypes="ind" restrictToRelationshipTypes="responsible">
     <l>^ca_entities.preferred_labels.displayname</l> (is responsible for)<br/></unit>}}}
     {{{<unit relativeTo="ca_entities.related" delimiter=" " restrictToTypes="ind" restrictToRelationshipTypes="family">
     <l>^ca_entities.preferred_labels.displayname</l> (same family as)<br/></unit>}}}
    

    (Note that here, I restrict to "individual" types, but I have also lines for "org" type.)


    You can see an example here (it is in french):

    https://collections.univ-pau.fr/pub/index.php/Detail/objects/110

  • edited June 9

    Same problem in Pawtucket 1.7.14. I can confirm the problem reported by jeff above. The relationship_typename is always the same direction for both objects when using these templates. The proposed solutions do not fix that.

Sign In or Register to comment.