Hi all, I’m trying to create a custom xPDO-model+table. I manage to create the model-files using this description: Custom Models - xPDO | MODX Documentation
My schema:
<?xml version="1.0" encoding="UTF-8"?>
<model package="skattelistene"
baseClass="xPDOObject"
platform="mysql"
defaultEngine="MyISAM"
tablePrefix="skattelistene_"
phpdoc-package="skattelistene"
phpdoc-subpackage="model"
version="1.1">
<object class="person" table="person" extends="xPDOSimpleObject">
<field key="fornavn" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="etternavn" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="fodselsaar" dbtype="int" precision="4" phptype="string" null="false" default=""/>
<field key="postnummer" dbtype="varchar" precision="4" phptype="string" null="false" default=""/>
<field key="poststed" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="formue" dbtype="bigint" precision="20" phptype="string" null="false" default=""/>
<field key="inntekt" dbtype="bigint" precision="20" phptype="string" null="false" default=""/>
<field key="skatt" dbtype="bigint" precision="20" phptype="string" null="false" default=""/>
<field key="kommunenummer" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<index alias="fornavn" name="fornavn" primary="false" unique="false" type="BTREE">
<column key="fornavn" length="" collation="A" null="false"/>
</index>
<index alias="etternavn" name="etternavn" primary="false" unique="false" type="BTREE">
<column key="etternavn" length="" collation="A" null="false"/>
</index>
<index alias="fodselsaar" name="fodselsaar" primary="false" unique="false" type="BTREE">
<column key="fodselsaar" length="" collation="A" null="false"/>
</index>
<index alias="postnummer" name="postnummer" primary="false" unique="false" type="BTREE">
<column key="postnummer" length="" collation="A" null="false"/>
</index>
<index alias="poststed" name="poststed" primary="false" unique="false" type="BTREE">
<column key="poststed" length="" collation="A" null="false"/>
</index>
<index alias="kommunenummer" name="kommunenummer" primary="false" unique="false" type="BTREE">
<column key="kommunenummer" length="" collation="A" null="false"/>
</index>
</object>
</model>
I have created a Snippet (xPDO Generator) with the following code to generate the model-files:
$manager= $modx->getManager();
$modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$manager= $modx->getManager();
$generator= $manager->getGenerator();
$schema = 'assets/xPDO/schemas/skattelisteperson.mysql.schema.xml';
$target = 'assets/xPDO/sagat/';
$generator->parseSchema($schema,$target);
This gives me the following directory:
But I see that my mysql table is not created when browsing in MySqlAdmin.
I then try to create the database-table using this code:
$modx->addPackage('skattelistene','assets/xPDO/sagat/skattelistene/', 'skattelistene_');
$manager->createObjectContainer('person');
But this just gives me the errror: Could not load package metadata for package skattelistene.
What am I doing wrong? Is it failing to add the package because the table does not exist? How do I generate the DB-table based on the model? I though the $generator->parseSchema($schema,$target); would do that TBH.
I have spent many hours on this now, and have to admit that doing something as simple as defining a schema, generating a model and table is not very intutivie… either that or I’m just stupid.
My site is hosted in MODx Cloud.
Thanks all.!