Answers.Body: <p>I <em>think</em> this works but is it an acceptable solution:</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $criteria-&gt;section = 'checkin';
  
  $criteria-&gt;relatedTo = array(
       'targetElement' =&gt; $entry,
       'field' =&gt; $field
  );
  
  $checkin = craft()-&gt;elements-&gt;findElements($criteria);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-01T18:40:58.447Z
Answers.LastActivityDate: 2017-02-01T18:40:58.447Z
Answers.UserDisplayName: Alan A
Answers.Body: <p>I think you're looking for </p>
  
  <pre><code>$criteria-&gt;with = array('fieldHandle');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-01T19:03:18.277Z
Answers.LastActivityDate: 2017-02-01T19:11:28.727Z
Answers.LastEditDate: 2017-02-01T19:11:28.727Z
Answers.UserDisplayName: nullvariable
Body: <p>I am working on a Craft plugin.</p>
  
  <p>I have a main entities are 'Courses' and 'Entries'. If I click on an Entries in the CMS there is an option to select and associated 'Course'.</p>
  
  <p>In my controller I can get a Course as follows:</p>
  
  <pre><code>$course = craft()-&gt;entries-&gt;getEntryById($variables['pathId']);
  </code></pre>
  
  <p>So far so good, but now I want to get all related 'Entries', so I do the following:</p>
  
  <pre><code>$entries=$course-&gt;entries-&gt;find();
  </code></pre>
  
  <p>This gives the following error:</p>
  
  <pre><code>Property "Craft\EntryModel.entries" is not defined.  
  </code></pre>
  
  <p>What am I doing wrong? Clearly the two are related so why isn't this method working?</p>
  
Tags: <plugin-development><relations><models><query>
Title: Plugin development - Querying related data
ThreadText: # Plugin development - Querying related data
  
  (Asked by: username_0 on 2017-02-01)
  
  I am working on a Craft plugin.
  
  I have a main entities are 'Courses' and 'Entries'. If I click on an Entries in the CMS there is an option to select and associated 'Course'.
  
  In my controller I can get a Course as follows:
  
  ```
  $course = craft()->entries->getEntryById($variables['pathId']);
  
  ```
  
  So far so good, but now I want to get all related 'Entries', so I do the following:
  
  ```
  $entries=$course->entries->find();
  
  ```
  
  This gives the following error:
  
  ```
  Property "Craft\EntryModel.entries" is not defined.  
  
  ```
  
  What am I doing wrong? Clearly the two are related so why isn't this method working?
  
  **Tags:** plugin-development, relations, models, query
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-02-01. Score: 1
  
  I *think* this works but is it an acceptable solution:
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::Entry);
  $criteria->section = 'checkin';
  
  $criteria->relatedTo = array(
       'targetElement' => $entry,
       'field' => $field
  );
  
  $checkin = craft()->elements->findElements($criteria);
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2017-02-01. Score: 1
  
  I think you're looking for
  
  ```
  $criteria->with = array('fieldHandle');
  
  ```
  
  
  ---
  
  