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.

  • 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?
    – a-am
    Jan 10, 2015 at 21:55

1 Answer 1


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.

  • Any way you could share the code you used to do this?
    – JBB
    Aug 13, 2015 at 7:07
  • @JarrettBarnett I followed Crafts internal ElementCriteriaModel & ElementsService. The customization came in with the BuildElementsQuery method you find in ElementsService. View comments here: craftcms.stackexchange.com/questions/5134/… There is a link to a plugin that helped me move in the right direction.
    – a-am
    Aug 20, 2015 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.