Hey folks, Can anyone give me a clue, please, as to why this code…
[[migxLoopCollection?
&packageName=`Dccontent`
&classname=`Dccontent\Model\dcTag`
&joins=`[{"alias":"ContentTag","class":"Dccontent\\Model\\dcContentTag"}]`
&where=`[{"ContentTag.content_id":"[[+id]]"}]`
&tpl=`@CODE:{{+name}}`
&outputSeparator=`,`
]]
…gives this error?
xPDO.php : 667) Could not load class: dcContentTag from mysql.dccontenttag
This code tells me the class is loading…
return class_exists('Dccontent\Model\dcContentTag') ? "Found!" : "Not found!";
MODX GPT just told me that MIGX may be “being a diva!” I think MODX GPT, like many of us, is just finding the documentation is out of date… very frustrating because Bruno’s Extra is fabulous.
Please help!
Can you provide the schema you are using?
And what version of MIGX is installed?
OllyConnelly:
&packageName=`Dccontent`
In MODX 3, the package should already get added by the bootstrap.php
file, so this property is most likely not necessary.
If the relationship is already defined in the schema, then you don’t have to specify the “class”.
Thank you Harry.
I am using MODX 3.1.1-pl with MIGX 3.0.2-beta1. And here is my schema.
<?xml version="1.0" encoding="UTF-8"?>
<model package="Dccontent\Model" baseClass="xPDO\Om\xPDOObject" platform="mysql" defaultEngine="InnoDB" phpdoc-package="" phpdoc-subpackage="" version="3.0">
<!-- dc_format table -->
<object class="dcFormat" table="dc_format" extends="xPDO\Om\xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" />
<field key="description" dbtype="text" phptype="string" null="true" />
<aggregate alias="Content" class="dcContent" local="id" foreign="format_id" cardinality="many" owner="local" />
</object>
<!-- dc_tag table -->
<object class="dcTag" table="dc_tag" extends="xPDO\Om\xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" />
<composite alias="ContentTag" class="dcContentTag" local="id" foreign="content_id" cardinality="many" owner="local" />
</object>
<!-- dc_content table -->
<object class="dcContent" table="dc_content" extends="xPDO\Om\xPDOSimpleObject">
<!-- Foreign key to dc_format -->
<field key="format_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
<field key="format" dbtype="text" phptype="string" null="true" />
<field key="sticky" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="title" dbtype="text" phptype="string" null="true" />
<field key="strapline" dbtype="text" phptype="string" null="true" />
<field key="excerpt" dbtype="text" phptype="string" null="true" />
<field key="content" dbtype="longtext" phptype="string" null="true" />
<field key="image" dbtype="varchar" precision="255" phptype="string" null="true" />
<field key="bg_image" dbtype="varchar" precision="255" phptype="string" null="true" />
<field key="link" dbtype="text" phptype="string" null="true" />
<field key="video" dbtype="text" phptype="string" null="true" />
<field key="source" dbtype="text" phptype="string" null="true" />
<field key="tag_id" dbtype="text" phptype="string" null="true" />
<field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="publishedon" dbtype="datetime" phptype="datetime" null="true" />
<field key="publishedby" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="createdby" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
<field key="editedon" dbtype="datetime" phptype="datetime" null="true" />
<field key="editedby" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
<field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="deletedon" dbtype="datetime" phptype="datetime" null="true" />
<field key="deletedby" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
<!-- Relationships -->
<aggregate alias="Format" class="dcFormat" local="format_id" foreign="id" cardinality="one" owner="foreign" />
<composite alias="ContentTag" class="dcContentTag" local="id" foreign="content_id" cardinality="many" owner="local" />
</object>
<!-- dc_content_tag table (many-to-many relationship between dc_content and dc_tag) -->
<object class="dcContentTag" table="dc_content_tag" extends="xPDO\Om\xPDOSimpleObject">
<field key="content_id" dbtype="int" precision="10" phptype="integer" null="false" />
<field key="tag_id" dbtype="int" precision="10" phptype="integer" null="false" />
<!-- Relationships -->
<aggregate alias="Content" class="dcContent" local="content_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Tag" class="dcTag" local="tag_id" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>
In your schema, make sure that the classes in the relationships also contain the namespace. E.g. <composite class="Dccontent\Model\dcContentTag" ... />
.
Also, the relationship “ContentTag” in the class “dcTag” has the wrong value for the “foreign” attribute. It should be foreign="tag_id"
instead of foreign="content_id"
.
With these changes it seems to work when I test it:
(Simplified) schema:
<?xml version="1.0" encoding="UTF-8"?>
<model package="Dccontent\Model\" baseClass="xPDO\Om\xPDOObject" platform="mysql" defaultEngine="InnoDB" version="3.0">
<object class="dcTag" table="dc_tag" extends="xPDO\Om\xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" />
<composite alias="ContentTag" class="Dccontent\Model\dcContentTag" local="id" foreign="tag_id" cardinality="many" owner="local" />
</object>
<object class="dcContentTag" table="dc_content_tag" extends="xPDO\Om\xPDOSimpleObject">
<field key="content_id" dbtype="int" precision="10" phptype="integer" null="false" />
<field key="tag_id" dbtype="int" precision="10" phptype="integer" null="false" />
<aggregate alias="Tag" class="Dccontent\Model\dcTag" local="tag_id" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>
Snippet call:
[[migxLoopCollection?
&classname=`Dccontent\Model\dcTag`
&joins=`[{"alias":"ContentTag"}]`
&where=`[{"ContentTag.content_id":"[[+id]]"}]`
&tpl=`@CODE:{{+name}}`
&outputSeparator=`,`
]]
2 Likes
Thank you Harry, that does indeed work. It transpired I’d mangled the directory structure in my component so at first your code did not work and that took me some time to realise and work out but, correcting my directory structure, it does work. Thank you.
1 Like
system
Closed
April 6, 2025, 2:07pm
6
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.