Answers.Body: <p>If I'm following you correctly, seems like you could override your Model's <a href="https://craftcms.com/classreference/models/BaseModel#getAttribute-detail" rel="nofollow"><code>getAttribute</code></a> method to do something like this completely untested code:</p>
  
  <pre><code>public function getAttribute($name, $flattenValue = false)
  {
      if ($name == 'location' &amp;&amp; $flattenValue != false)
      {
          $criteria = craft()-&gt;elements-&gt;getCriteria('MyPlugin_MyElementType');
          $criteria-&gt;location = parent::getAttribute($name, $flattenValue);
          return $criteria;
      }
  
      return parent::getAttribute($name, $flattenValue);
  }
  </code></pre>
  
  <p>If I'm not following you correctly, then that was pointless.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-15T21:02:01.387Z
Answers.Text: The code is now tested and works. Thank you.
Answers.UserDisplayName: a-am
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-15T21:02:41.033Z
Answers.Text: Awesome... lucky guess!
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-15T20:47:49.027Z
Answers.LastActivityDate: 2016-08-15T22:32:42.367Z
Answers.LastEditDate: 2016-08-15T22:32:42.367Z
Answers.UserDisplayName: Brad Bell
Body: <p>In one of my Plugin's CP templates I am using a element select field to grab elements from a custom element type.  This field saves an array of element ids to a specific record's attribute called "location".  How do you return an element criteria model instead of the array of ids when the model attribute is called via twig?</p>
  
  <pre><code>// Model
  protected function defineAttributes()
  {
      return array_merge(parent::defineAttributes(), array(
          'location'          =&gt; Attributetype::Mixed,
          'specificLocation'  =&gt; AttributeType::String,
          'registration'      =&gt; AttributeType::Mixed,
      ));
  }
  
  // Front end template
  {{ craft.pluginname.variable.location }}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-15T16:48:28.890Z
Comments.Text: What do you mean by "plugin's fields"? Are you referring to the plugin's settings? Or a custom fieldtype?
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-15T17:59:15.017Z
Comments.Text: @MatsMikkelRummelhoff it is field associated with the plugin's custom attributes not associate with settings or a custom field type.
Comments.UserDisplayName: a-am
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-15T18:07:22.557Z
Comments.Text: Sorry, I might be dense but I'm not following - there's no such thing as "plugin attributes". It might help if you shared some code.
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-15T18:34:59.640Z
Comments.Text: I have updated my question.
Comments.UserDisplayName: a-am
Tags: <plugin-development><elementcriteriamodel>
Title: Return element criteria model from attribute of a model
ThreadText: # Return element criteria model from attribute of a model
  
  (Asked by: username_0 on 2016-08-15)
  
  In one of my Plugin's CP templates I am using a element select field to grab elements from a custom element type. This field saves an array of element ids to a specific record's attribute called "location". How do you return an element criteria model instead of the array of ids when the model attribute is called via twig?
  
  ```
  // Model
  protected function defineAttributes()
  {
      return array_merge(parent::defineAttributes(), array(
          'location'          => Attributetype::Mixed,
          'specificLocation'  => AttributeType::String,
          'registration'      => AttributeType::Mixed,
      ));
  }
  
  // Front end template
  {{ craft.pluginname.variable.location }}
  
  ```
  
  **Tags:** plugin-development, elementcriteriamodel
  
  > **Comments:**
  > **username_1**: What do you mean by "plugin's fields"? Are you referring to the plugin's settings? Or a custom fieldtype?  
  > **username_0**: @username_1 it is field associated with the plugin's custom attributes not associate with settings or a custom field type.  
  > **username_1**: Sorry, I might be dense but I'm not following - there's no such thing as "plugin attributes". It might help if you shared some code.  
  > **username_0**: I have updated my question.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-08-15. Score: 2 | Accepted answer
  
  If I'm following you correctly, seems like you could override your Model's [`getAttribute`](https://craftcms.com/classreference/models/BaseModel#getAttribute-detail) method to do something like this completely untested code:
  
  ```
  public function getAttribute($name, $flattenValue = false)
  {
      if ($name == 'location' && $flattenValue != false)
      {
          $criteria = craft()->elements->getCriteria('MyPlugin_MyElementType');
          $criteria->location = parent::getAttribute($name, $flattenValue);
          return $criteria;
      }
  
      return parent::getAttribute($name, $flattenValue);
  }
  
  ```
  
  If I'm not following you correctly, then that was pointless.
  
  > **Comments:**
  > **username_0**: The code is now tested and works. Thank you.  
  > **username_2**: Awesome... lucky guess!  
  
  ---
  
  