Xpdo3 | Instantiated a derived class MiApi\Model\MiChecklistItems that is not a subclass of

I have a model and this is a part of it, that gives me this error:

[2023-03-31 10:24:37] (ERROR @/vendor/xpdo/xpdo/src/xPDO/Om/xPDOObject.php : 359) Instantiated a derived class MiApi\Model\MiChecklistItems that is not a subclass of the requested class MiApi\Model\MiChecklistValues

This is that part:

    <object class="MiChecklistItems" table="mi_checklist_items" extends="xPDO\Om\xPDOObject">
        <field key="ID" dbtype="int" precision="20" phptype="integer" null="false" index="pk" generated="native"/>
        <field key="title" dbtype="varchar" precision="255" phptype="string" null="false"/>
        <field key="description" dbtype="varchar" precision="255" phptype="string" null="false"/>
        <field key="field_type" dbtype="varchar" precision="20" phptype="string" null="false"/>
        <field key="field_name" dbtype="varchar" precision="20" phptype="string" null="false"/>
        <field key="field_value" dbtype="text" phptype="string" null="true"/>
        <field key="method" dbtype="text" phptype="string" null="true"/>
        <field key="parent" dbtype="int" precision="20" phptype="integer" default="0"/>
        <field key="method_parent" dbtype="int" precision="20" phptype="integer" default="0"/>
        <field key="section_id" dbtype="varchar" precision="255" phptype="string"/>
        <field key="sort" dbtype="int" precision="3" phptype="integer" default="0"/>

        <index alias="ID" name="ID" primary="true" unique="true" type="BTREE">
            <column key="ID" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="MiChecklistSection" class="MiApi\Model\MiChecklistSections" local="section_id" foreign="ID" cardinality="one" owner="foreign"/>
        <composite alias="MiChecklistValue" class="MiApi\Model\MiChecklistValues" local="ID" foreign="checkitem_id" cardinality="many" owner="local"/>

    </object>

    <object class="MiChecklistValues" table="mi_checklist_values" extends="xPDO\Om\xPDOObject">
        <field key="ID" dbtype="int" precision="20" phptype="integer" null="false" index="pk" generated="native"/>
        <field key="taskslip_id" dbtype="int" precision="2" phptype="integer" default="0"/>
        <field key="checkitem_id" dbtype="int" precision="2" phptype="integer" default="0"/>
        <field key="value" dbtype="text" phptype="string" null="false"/>
        <field key="parent" dbtype="int" precision="20" phptype="integer" default="0"/>
        <field key="user_id" dbtype="int" precision="20" phptype="integer" null="false" default="0"/>
        <field key="date" dbtype="datetime" phptype="datetime" null="false"/>

        <index alias="ID" name="ID" primary="true" unique="true" type="BTREE">
            <column key="ID" length="" collation="A" null="false"/>
        </index>

        <aggregate alias="MiTaskSlip" class="MiApi\Model\MiTaskSlips" local="taskslip_id" foreign="ID" cardinality="one" owner="foreign"/>
        <aggregate alias="MiChecklistItem" class="MiApi\Model\MiChecklistItems" local="checkitem_id" foreign="ID" cardinality="one" owner="foreign"/>

    </object>

What could be the problem? I think that the model is ok, but maybe i made a mistake? ore used a reserved column name?

Thanks for any help.

When exactly do you get this error? While parsing the schema or when you try to use your custom classes?

When i use them in my classes.

The schema looks ok (at least the part you shared) and when I test it, a simple getCollection() call seems to work correctly.

Can you share the code you use?
Maybe it’s just that you use $modx->newQuery() for one class, and then getObject()/getCollection() for a different one.

        $c = $this->xpdo->newQuery(MiChecklistItems::class);
        $c->leftJoin(
            MiChecklistValues::class,
            'MiChecklistValues',
            'MiChecklistItems.ID = MiChecklistValues.checkitem_id AND MiChecklistValues.taskslip_id = ' . $taskslip_id
        );
        $c->where([
            'MiChecklistItems.sliptype_id' => $sliptype_id
        ]);
        if (null !== $section_id) {
            $c->where([
                'MiChecklistItems.section_id' => $section_id
            ]);
        }
        $c->select(
            'MiChecklistValues.*,MiChecklistItems.*'
        );

        $checklistItems = $this->xpdo->getCollection(MiChecklistValues::class, $c);

I believe you have to use the same class here.
If it has to be “MiChecklistValues” for the getCollection call, then try using the same class (and a rightJoin to “MiChecklistItems”) in the query.

I see my error now… indeed the two different classnames…

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”.