pdoResources &select syntax

I’m wondering how to use pdoResources to select values from a custom table.

This works to enable the placeholders in the corresponding &tpl:-

[[!pdoResources?
&class=`Dcposts\Model\dcPosts`
&includeTVs=`dcVideoTV`
&limit=`1`
&tpl=`dcVideoTpl`
&where=`{"format":"video"}`
&sortdir=`ASC`
]] 

But adding this (to reduce the query size, which is sensible, no?) breaks the output:-

&select = `{"mxdc_dc_posts":"id,title,video,publishedon"}`

mxdc_dc_posts is the table I created using Migx and which is referenced also with the &class and via the &includeTVs.

Don’t use the name of the database table in the &select, use the name of the class.

I think this should work:

[[!pdoResources?
    &class=`Dcposts\Model\dcPosts`
    ...
    &select=`{"Dcposts\\Model\\dcPosts":"id,title,video,publishedon"}`
]] 

(Make sure to use double backslashes \\ in the JSON)


Also, are you sure the property &includeTVs=`dcVideoTV` works in this case? I don’t know your database schema, but this probably generates the message “Could not join TVs to the class Dcposts\Model\dcPosts that is not a subclass of the modResource” in the MODX error log.

1 Like

Ty Harry. (Splendid vids on YT, BTW, ty again.)

I’ve adjusted my call to this but still no luck. If I omit the &tpl the page resolves with the raw json, else blank.

[[!pdoResources?
&class=`Dcposts\Model\dcPosts`
&where=`{"format":"video"}`    
&select=`{"Dcposts\\Model\\dcPosts":"id,title,strapline,excerpt"}`
&limit=`1`
&sortdir=`DESC`
&tpl=`dcVideoTpl`
]] 

Modx 3.0.3 with Migx 3.0.0-beta1.

So the problem is the template?!
Does the chunk “dcVideoTpl” exist? Maybe it’s just a typo.

Is there something special in this chunk that could break the output? (An unpatched version of Modx 3.0.3 still has some parser issues.)
Does an inline template (like &tpl=`@INLINE <li>{{+title}} ({{+id}})</li>` work correctly?

1 Like

Yes! Solved.

It appears that I broke the output with a redundant * call wrapping the rest of the tpl’s content:-

[[+format:is=`video`:then=`

…placeholders…

`]]

  • Format already specified in the pdoResources call, I deleted this conditional and the output parses as requested.

Thank you Harry. And thank you for such fast replies, very kind, I am most grateful.