Element API using the entries field to display related content from a separate section I've seen similar questions but none seem to help.
I have two sections named jobs and jobDescriptions. I'm using the entries field to pull in a description field from the jobDescriptions section to the jobs entry. I need to output the related description field to the element api but I'm stuck. No idea where to go from here.
The other issue is that I also have a field in the jobs section that is named descriptionOverride. I want to show the descriptionOverride field if it has a value instead of the related field.
&lt;?php

use craft\elements\Entry;
use craft\helpers\UrlHelper;
use craft\elements\Tag;
return [
    'endpoints' =&gt; [
        'jobs.json' =&gt; function() {

            return array(
                'serializer' =&gt; 'jsonFeed',
                'elementType' =&gt; Entry::class,
                'criteria' =&gt; array('section' =&gt; 'jobs'),
                'transformer' =&gt; function(Entry $entry) {

                    return array(
                        'title' =&gt; $entry-&gt;title,

                        {# pulling the description field from the jobDescriptions section using the entries field relatedJobDescriptions in the jobs section. I'm obviously
way off base. #}
                        'description' =&gt; $entry-&gt;relatedJobDescription-&gt;description,
                    );
                },
                'meta' =&gt; array(
                    'description' =&gt; '',
                ),
                'pretty' =&gt; true,
            );
        },

        'jobs2.json' =&gt; function() {

            return [
                'serializer' =&gt; 'jsonFeed',
                'elementType' =&gt; Entry::class,
                'criteria' =&gt; ['section' =&gt; 'jobs'],
                'transformer' =&gt; function(Entry $entry) {

                    return [
                        'title' =&gt; $entry-&gt;title,
                    ];
                },
                'meta' =&gt; [
                    'description' =&gt; 'Recent news from Happy Lager',
                ],
                'pretty' =&gt; true,
            ];
        },
    ],
];
If relatedJobDescription is an Entries field, accessing the field from your jobs entry will not return the selected jobDescriptions entry directly. Instead, you will get an EntryQuery which you can use to get the selected jobDescriptions from the database. See Working with Entries Field Data and Querying Entries.
To get the jobDescriptions entry, you can use ElementQuery::one() (if your field allowed for multiple related jobDescriptions entries, you could use ElementQuery::all() instead).
Regarding the descriptionOverride, that's just a matter of checking if the override field contains some text and if it does, return it instead of the related job description.
Something like this should work:
// get the entry holding the related job description
$relatedJobDescriptionEntry = $entry-&gt;relatedJobDescription-&gt;one();
// handle an empty relatedJobDescriptions field gracefully
$relatedJobDescription = $relatedJobDescriptionEntry ? $relatedJobDescriptionEntry-&gt;description : '';
// get the description override from the current entry
$descriptionOverride = $entry-&gt;descriptionOverride;
return array(
    'title' =&gt; $entry-&gt;title,
    // return either the overridden description or the related job description
    'description' =&gt; ((string) $descriptionOverride) ?: $relatedJobDescription,
);

You can optimize this further to only retrieve the related job description if the override is not set.