We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34193
    • 330 Posts
    ok first off not sure if this or the revo board is the best place for this if it’s in the wrong place mods please feel free to move.

    I am trying to set up a many to many relationship and build a schema for it. Using the docs I got this far.

    I have 3 tables as follows
     modx_VLE_Pupils
    	Field           Type            Null    Default
    	RoleNum	int(11)			No	None	auto_increment	 	 	 	 	 	 	
    	FirstName	varchar(30)	No	None		 	 	 	 	 	 	 
    	MiddleName	varchar(30)	Yes	NULL		 	 	 	 	 	 	 
    	SurName	        varchar(30)	No	None		 	 	 	 	 	 	 
    	DOB	        date		No	None		 	 	 	 	 	 	
    	Gender	        varchar(1)	No	None		 	 	 	 	 	 	 
    	YearGroup	int(11)		Yes	NULL		 	 	 	 	 	 	
    	Group	        varchar(2)	Yes	NULL		 	 	 	 	 	 	 
    	House	        varchar(6)	Yes	NULL		 	 	 	 	 	 	 
    	Religion	        varchar(20)	Yes	NULL		 	 	 	 	 	 	 
    	HomeLang	        varchar(20)	Yes	NULL		 	 	 	 	 	 	 
    	Status	        varchar(8)	No	None		 	 	 	 	 	 	 
    


    modx_VLE_Parents
    	Field	        Type	        Null	Default
    	ParentId	        int(11)		No	None	auto_increment	 	 	 	 	 	 	
    	FirstName	varchar(30)	No	None		 	 	 	 	 	 	 
    	SurName	        varchar(30)	No	None		 	 	 	 	 	 	 
    	MobileNum	varchar(11)	Yes	NULL		 	 	 	 	 	 	 
    	LandNum	        varchar(11)	Yes	NULL		 	 	 	 	 	 	 
    	Address1	        varchar(30)	Yes	NULL		 	 	 	 	 	 	 
    	Address2	        varchar(30)	Yes	NULL		 	 	 	 	 	 	 
    	Address3	        varchar(30)	Yes	NULL		 	 	 	 	 	 	 
    	PostCode	        varchar(8)	Yes	NULL		 	 	 	 	 	 	 
    	Priority 	int(11)		No	None		 	 	 	 	 	 	
    

    modx_VLE_Pupils-Parent
    	Field	        Type		Null	Default	
    	PupilRoleNum	int(11)		No	None		 	 	 	 	 	 	
    	ParentRoleNum	int(11)		No	None		 	 	 	 	 	 	

    vle.mysql.schema.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="VLE" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM"
         phpdoc-package="VLE" phpdoc-subpackage="">
    
        <object class="VLEPupil" table="VLE_Pupils" extends="xPDOObject">
            <field key="RoleNum"    dbtype="int"     precision="11" phptype="integer" null="false" default="" index="index"/>
            <field key="FirstName"  dbtype="varchar" precision="30" phptype="string" null="false" default="" />
    	<field key="MiddleName" dbtype="varchar" precision="30" phptype="string" null="true" default="" />
    	<field key="SurName"    dbtype="varchar" precision="30" phptype="string" null="false" default="" />
    	<field key="DOB"        dbtype="date"    precision=""  phptype="date" null="false" default="" />
    	<field key="Gender"     dbtype="varchar" precision="1" phptype="string" null="false" default="" />
    	<field key="YearGroup"  dbtype="int"     precision="11" phptype="integer" null="true" default="" />
    	<field key="Group"      dbtype="varchar" precision="2"  phptype="string" null="true" default="" />
    	<field key="House"      dbtype="varchar" precision="6"  phptype="string" null="true" default="" />
    	<field key="Religion"   dbtype="varchar" precision="20" phptype="string" null="true" default="" />
    	<field key="HomeLang"   dbtype="varchar" precision="20" phptype="string" null="true" default="" />
    	<field key="Status"     dbtype="varchar" precision="8"  phptype="string" null="false" default="" />
    
             <composite alias="VLEPupilParent" class="VLEPupilParent" local="RoleNum" foreign="PupilRoleNum" cardinality="many" owner="local" />
        </object>
    
        <object class="VLEParent" table="VLE_Parents" extends="xPDOObject">
            <field key="ParentId"   dbtype="int"     precision="11" phptype="integer" null="false" default="" index="index"/>
            <field key="FirstName"  dbtype="varchar" precision="30" phptype="string" null="false" default="" />
            <field key="SurName"    dbtype="varchar" precision="30" phptype="string" null="false" default="" />
    	<field key="MobileNum"  dbtype="varchar" precision="11" phptype="string" null="true" default="" />
    	<field key="LandNum"    dbtype="varchar" precision="11" phptype="string" null="true" default="" />
    	<field key="Address1"   dbtype="varchar" precision="30" phptype="string" null="true" default="" />
    	<field key="Address2"   dbtype="varchar" precision="30" phptype="string" null="true" default="" />
    	<field key="Address3"   dbtype="varchar" precision="30" phptype="string" null="true" default="" />
    	<field key="PostCode"   dbtype="varchar" precision="8"  phptype="string" null="true" default="" />
    	<field key="Priority"   dbtype="int"     precision="11" phptype="integer" null="false" default="" />
    
            <composite alias="VLEPupilParent" class="VLEPupilParent" local="ParentId" foreign="ParentRoleNum" cardinality="many" owner="local" />
        </object>
    
        <object class="VLEPupilParent" table="VLE_Pupils-Parent" extends="xPDOObject">
            <field key="PupilRoleNum"   dbtype="int" precision="11" phptype="integer" null="false" default="" />
            <field key="ParentRoleNum"  dbtype="int" precision="11" phptype="integer" null="false" default="" />
    
            <aggregate alias="Pupil" class="VLEPupil" local="PupilRoleNum" foreign="RoleNum" cardinality="one" owner="foreign" />
            <aggregate alias="Parent" class="VLEParent" local="ParentRoleNum" foreign="ParentId" cardinality="one" owner="foreign" />
        </object>
    </model>
    


    build.VLE.php
    
    <?php
    // sets up the MODX_ defines and the paths to the xPDO core
    // you'll want to change this first line to point to the actual MODx install path
    define('MODX_BASE_PATH', dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/development/');
    define('MODX_CORE_PATH', MODX_BASE_PATH.'core/');
    require_once (MODX_CORE_PATH . 'config/config.inc.php');
    include_once (MODX_CORE_PATH . 'model/modx/modx.class.php');
    
    // first get the actual trunk path
    $trunk = dirname(dirname(dirname(__FILE__)));
    
    // create the modx object and load the modPackageBuilder class
    $modx = new modX();
    $modx->loadClass('transport.modPackageBuilder','',false, true);
    $builder = new modPackageBuilder($modx);
    
    // build the schema, using the PackageBuilder's buildSchema function. It takes 2 parameters:
    // - the location of the model directory where you want the files to generate to
    // - the schema xml file
    
    $builder->buildSchema($trunk.'/assets/model/',$trunk.'/_build/schema/vle.mysql.schema.xml');
    
    echo 'Finished!';
    exit();
    ?>
    
    


    When I run this i get the following error

    Fatal error: Call to a member function load() on a non-object in /home/removed part of path/public_html/development/core/model/modx/transport/modpackagebuilder.class.php on line 81

    any ideas what I am doing wrong here
      • 28215
      • 4,149 Posts
      After $modx = new $modX(), add this line:

      $modx->initialize('mgr');
      

        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 34193
        • 330 Posts
        Thanks that seems to have worked. Might want to up date http://svn.modxcms.com/docs/display/~splittingred/2008/06/26/Writing+a+3rd+Party+Component+in+MODx+Revolution,+Pt.+I as thats where I got that code from and that line is missing.
          • 28215
          • 4,149 Posts
          Fixed. Thanks.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com