I’m (still) struggeling a bit to create a correct schema for my custom package using migxdb. My goal is to show references from a client in certain categories. One reference can have multiple categories assigned and also one category can have multiple references linked, therefore my conclusion was a many to many setup:
show schema
<?xml version="1.0" encoding="UTF-8"?>
<model package="Referenzen\Model\" baseClass="xPDO\Om\xPDOObject" platform="mysql" defaultEngine="InnoDB" phpdoc-package="" phpdoc-subpackage="" version="3.0">
<object class="Kategorie" table="referenzen_kategorien" extends="xPDO\Om\xPDOSimpleObject">
<field key="name" dbtype="varchar" phptype="string" precision="100" null="false" default="" index="index"/>
<field key="description" dbtype="text" phptype="string" null="false" default="" />
<field key="image" dbtype="text" phptype="string" null="false" default="" />
<composite alias="Referenzen" class="Referenzen\Model\KategorieReferenz" local="id" foreign="kategorie_id" cardinality="many" owner="local" />
<index alias="name" name="name" primary="false" unique="false" type="BTREE">
<column key="name" length="" collation="A" null="false" />
</index>
</object>
<object class="Referenz" table="referenzen" extends="xPDO\Om\xPDOSimpleObject">
<field key="title" dbtype="varchar" phptype="string" precision="190" null="false" default="" index="index" />
<field key="description" dbtype="text" phptype="string" null="false" default="" />
<field key="images" dbtype="text" phptype="string" null="false" default="" />
<composite alias="KategorienZuReferenzen" class="Referenzen\Model\KategorieReferenz" local="id" foreign="referenz_id" cardinality="many" owner="local" />
<index alias="title" name="title" primary="false" unique="false" type="BTREE">
<column key="title" length="" collation="A" null="false" />
</index>
</object>
<object class="KategorieReferenz" table="referenzen_kategorie_referenz" extends="xPDOSimpleObject">
<field key="referenz_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
<field key="kategorie_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
<aggregate alias="Referenz" class="Referenzen\Model\Referenz" local="referenz_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Kategorie" class="Referenzen\Model\Kategorie" local="kategorie_id" foreign="id" cardinality="one" owner="foreign" />
<index alias="referenz_id" name="referenz_id" primary="false" unique="false" type="BTREE">
<column key="referenz_id" length="" collation="A" null="false" />
</index>
<index alias="kategorie_id" name="kategorie_id" primary="false" unique="false" type="BTREE">
<column key="kategorie_id" length="" collation="A" null="false" />
</index>
</object>
</model>
I’ve read through these docs which helped me creating the above schema, but now I’m stuck when I actually try to link the two parts together in the CMP.
Do I have to create an additional field under references where I can store the IDs of the selected categories? To be clear, I know how to create a dropdown of the values from the category table using a @CHUNK
input with a migxLoopCollection
call.
What I don’t yet understand is how this works in the background as I would assume my connecting table from the “KategorieReferenz” class should be populated somehow.
MODX 3.0.5
MIGX 3.0.2-beta1