Element API: return a related entry's asset data with entry data I'm producing a list of entries that each use an image asset from a related entry.  I see in this ticket how to get an asset's data, and I've combined that with how I learned to output an object's data from a Mijingo video (via the array_map function).  

This approach works, but seeing how there are about 130 entries in the section, the load time is a whopping 2.31s versus when I take out the related entry's asset code, which then results in a much smaller 500ms load time.  Is there a better way to access this data?

Here's the code I'm using:

return [
    'endpoints' =&gt; [
        'api/pressEntries.json' =&gt; [
            'elementType' =&gt; 'Entry',
            'criteria' =&gt; ['section' =&gt; 'pressEntries'],
            'transformer' =&gt; function(EntryModel $entry) {
                return [
                    'id'                =&gt; $entry-&gt;id,
                    'title'             =&gt; $entry-&gt;title,
                    'slug'              =&gt; $entry-&gt;slug,
                    'postDate'          =&gt; $entry-&gt;postDate,
                    'type'              =&gt; $entry-&gt;type-&gt;name,
                    'url'               =&gt; $entry-&gt;url,
                    'jsonUrl'           =&gt; UrlHelper::getUrl("api/press/{$entry-&gt;id}.json"),
                    'relatedRecording'  =&gt; array_map(function(EntryModel $album) {
                        $data = [
                            'id'    =&gt; $album-&gt;id,
                            'title' =&gt; $album-&gt;title,
                        ];

                        $artwork = $album-&gt;recordingArtwork-&gt;first();
                        if ($artwork) {
                            $data['artwork'] = $artwork-&gt;url;
                        }
                        return $data;

                    }, $entry-&gt;relatedRecording-&gt;find()),
                ];
            },
        ]
    ]
];
Sounds like you need to do some eager loading of your assets.

Here are some examples of how to do that in the Element API plugin:

ElementAPI handling CategoryModel and returning a heirachical object

Getting categories in elementAPI performance issues and help required