Eager loading EntryElementType from custom ElementType in a plugin trying to get my head wrapped around eager loading element relationships in my plugin. A little context, I’m working on a navigation module and I have a Node element type, which belongs to a Navigation and has one Entry element type:

public function defineRelations(){
return array(
  'element'    =&gt; array(static::BELONGS_TO, 'ElementRecord', 'id', 'required' =&gt; true, 'onDelete' =&gt; static::CASCADE),
  'navigation' =&gt; array(static::BELONGS_TO, 'Navee_NavigationRecord', 'required' =&gt; true, 'onDelete' =&gt; static::CASCADE),
  'entry'      =&gt; array(static::HAS_ONE, 'EntryRecord', 'entryId', 'required' =&gt; false),
);


}

When I’m getting my nodes, I’d like to eager load the entry for each node. This is where I’m just sort of falling down on they syntax. If I currently have (without eager loading):

$criteria = craft()-&gt;elements-&gt;getCriteria('Navee_Node');


Would I eager load the entries by doing something like:

$criteria = craft()-&gt;elements-&gt;getCriteria('Navee_Node')-&gt;with(ElementType::Entry);


I should note that what I'm really trying to do is pull the uri for each related entry without having to run an additional query every time I iterate over the navigation. So maybe my thinking is wrong and I don't need to eager load the entire EntryElement type, but just a particular field?

Thanks so much in advance for any insight you can provide.

MW
The article on StraightUpCraft should be able to point you in the right direction. PHP stuff is towards the bottom of the article.

Examples of Eager Loading Elements in Twig and PHP

Also this Craft hangout is worth watching, it gives a lot of detail on Eager loading. It's over an hour long though, so set yourself some time aside to watch it.

Eager loading Elements