How to show image on express entry detail associated entry

Any help would be greatly appreciated.

I'm trying to show a list of associated entries on an entry detail block. Just like this tutorial:

The only difference is I want to show an image in addition to text fields.
The other fields work correctly, I've added the image in the same manner however I get the following error

Call to a member function getRelativePath() on null

This is the code I'm using.

<?php $works =  $entry->getWorks(); ?>
<table class="table">
        <th>Primary Image</th>
    <?php if (count($works)) {
        foreach($works as $work) { ?>

rosie607 replied on at Permalink Reply
Finally figured out a solution.
I think the word 'work' was causing an issue as it's used to get the associated entity. It seems to be with the other fields but not the image field.
Therefore to I had to change the handle to thumbnail_primary_image rather than work_primary_image

Additionally the other fields are with underscores however the image field must use camel case to work. And needed a leading underscore rather than an uppercase character....

So i needed to change the code to


rather than