Answers.Body: <p>I found out I was not able to accomplish what I needed by using <strong>modifyElementsQuery</strong>.  So I created my own <strong>ElementCriteriaModel</strong> &amp; <strong>buildElementsQuery</strong> for my plugin. This allows the criteria to be built from my table directly instead of elements table.  </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T07:07:01.390Z
Answers.Text: Any way you could share the code you used to do this?
Answers.UserDisplayName: Jarrett Barnett
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-20T16:48:48.400Z
Answers.Text: @JarrettBarnett I followed Crafts internal ElementCriteriaModel & ElementsService.   The customization came in with the BuildElementsQuery method you find in ElementsService.  View comments here: http://craftcms.stackexchange.com/questions/5134/what-is-the-proper-way-to-fetch-items-from-a-custom-db-table-and-output-them-in/5201#comment7467_5201 There is a link to a plugin that helped me move in the right direction.
Answers.UserDisplayName: a-am
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-14T21:17:49.690Z
Answers.LastActivityDate: 2015-01-15T06:18:45.603Z
Answers.LastEditDate: 2015-01-15T06:18:45.603Z
Answers.UserDisplayName: a-am
Body: <p>I need to join my <strong>plugin's custom table</strong> to a an <strong>ElementCriteriaModel (ECM)</strong>. I am trying to use <strong>modifyElementsQuery</strong>. </p>
  
  <p>In the plugin's custom table, rows can share an element/entry via a separate id.</p>
  
  <p><strong>Can I achieve this by adding to the modifyElementsQuery? What would the query be to accomplish this?</strong> </p>
  
  <p>*My intention is to have an array of models for each row of my custom table, and each model will include my row data, in addition to the element's content it is related to.</p>
  
  <p><img src="https://i.sstatic.net/wWqpz.png" alt="Here is a visual helping to explain what I am trying to accomplish."></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-10T21:55:05.587Z
Comments.Text: I have tried adding a select for the columns of the custom table. Also I have added a join to my table element key id to the elements.id. Because my custom table has a many to one relationship to the elements table should this work?
Comments.UserDisplayName: a-am
Tags: <plugin-development><elementcriteriamodel><queries>
Title: Using modifyElementsQuery to get plugin's custom table data
ThreadText: # Using modifyElementsQuery to get plugin's custom table data
  
  (Asked by: username_0 on 2015-01-10)
  
  I need to join my **plugin's custom table** to a an **ElementCriteriaModel (ECM)**. I am trying to use **modifyElementsQuery**.
  
  In the plugin's custom table, rows can share an element/entry via a separate id.
  
  **Can I achieve this by adding to the modifyElementsQuery? What would the query be to accomplish this?**
  
  \*My intention is to have an array of models for each row of my custom table, and each model will include my row data, in addition to the element's content it is related to.
  
  ![Here is a visual helping to explain what I am trying to accomplish.](https://i.sstatic.net/wWqpz.png)
  
  **Tags:** plugin-development, elementcriteriamodel, queries
  
  > **Comments:**
  > **username_0**: I have tried adding a select for the columns of the custom table. Also I have added a join to my table element key id to the elements.id. Because my custom table has a many to one relationship to the elements table should this work?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-01-14. Score: 1 | Accepted answer
  
  I found out I was not able to accomplish what I needed by using **modifyElementsQuery**. So I created my own **ElementCriteriaModel** & **buildElementsQuery** for my plugin. This allows the criteria to be built from my table directly instead of elements table.
  
  > **Comments:**
  > **username_1**: Any way you could share the code you used to do this?  
  > **username_0**: @username_1 I followed Crafts internal ElementCriteriaModel & ElementsService.   The customization came in with the BuildElementsQuery method you find in ElementsService.  View comments here: http://craftcms.stackexchange.com/questions/5134/what-is-the-proper-way-to-fetch-items-from-a-custom-db-table-and-output-them-in/5201#comment7467_5201 There is a link to a plugin that helped me move in the right direction.  
  
  ---
  
  