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' => array(static::BELONGS_TO, 'ElementRecord', 'id', 'required' => true, 'onDelete' => static::CASCADE),
'navigation' => array(static::BELONGS_TO, 'Navee_NavigationRecord', 'required' => true, 'onDelete' => static::CASCADE),
'entry' => array(static::HAS_ONE, 'EntryRecord', 'entryId', 'required' => 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()->elements->getCriteria('Navee_Node');
Would I eager load the entries by doing something like:
$criteria = craft()->elements->getCriteria('Navee_Node')->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