We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8425
    • 159 Posts
    Hi,
    I'm re-using an existing component. I've added new columns to the database. I've updated also the schema xml file. How can I refresh the mapping since the new fields I have added cannot be accessed via the xPOD apis?
    Thanks.
      • 33976 ☆ A M B ☆
      • 571 Posts
      Hi eclipseTalk,

      One possible way can be to use $xpdo->getManager->addField() (see http://api.modx.com/revolution/2.1/_xpdo_om_xpdomanager.class.html#%5CxPDOManager::addField()).

      Another possible option can be, if you do not have any data in your table(s), to drop the tables and build the classes/create table(s) from your modified schema.

      Hope that will help
        • 8425
        • 159 Posts
        Thanks that helped.
          • 3749
          • 24,544 Posts
          You can also run $modx->parseSchema() on the new schema. That will create the new class and map files you need.

          There's code in the .zip file here to do that: http://bobsguides.com/custom-db-tables.html. You probably want to set &createSchema=`0` to avoid overwriting your updated schema. Back up your schema first.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 19980 ☆ A M B ☆
            • 275 Posts
            Thanks for this thread.
            As for the Bob's guide http://bobsguides.com/custom-db-tables.html I find it the only 1 way to become familiar with porting XPDO to MODX class ;-)

            However I got stuck on the step of addPackage in my snippet after createxpdoclasses code ran and finished with this report:

            [2012-01-09 02:02:53] (INFO @ /index.php)
            
            Schema file written to /mnt/web/content/core/components/certsfunction/schema/certsfunction.mysql.schema.xml
            [2012-01-09 02:02:53] (INFO @ /index.php)
            
            Schema file parsed -- Files written to /mnt/web/content/core/components/certsfunction/model/
            [2012-01-09 02:02:53] (INFO @ /index.php)
            
            FINISHED
            


            The createxpdoclasses code created the XML
            <?xml version="1.0" encoding="UTF-8"?>
            <model package="certsfunction" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
            	<object class="Certs" table="certs" extends="xPDOObject">
            		<field key="FILENUM" dbtype="varchar" precision="10" phptype="string" null="false" index="pk" />
            		<field key="COMPNO" dbtype="varchar" precision="3" phptype="string" null="true" index="index" />
            		<field key="LENDERNAME" dbtype="varchar" precision="35" phptype="string" null="true" />
            ..................
            for my Table: import_certs
            and php class
            <?php
            class Certs extends xPDOObject {}


            but the page with the following snippet 's code
            <?php
            $path = MODX_CORE_PATH . 'components/certsfunction/'; //echo $path;
            $result = $modx->addPackage('certsfunction',$path . 'model/','import_');
            if (! $result) {
              return 'failed to add package';
            } else {
              $output1 = '<p>added Package</p>';
            }
            
            $CERT = $modx->getCollection('Certs'); 
            $output1 .= '<p>Total: '. count($CERT) . '</p>';
            
            /*foreach($CERT as $quote) {
            
                $output .= '<p>LENDERNAME: ' . $quote->get('LENDERNAME');
                $output .= '<br />LOAN_ID: ' . $quote->get('LOAN_ID'). '</p>';
            }*/
            
            return $output;

              modx and ecommerce pro
              • 3749
              • 24,544 Posts
              Is addPackage() failing?

              I don't see anything obvious that's wrong. Did you check the core/components/certsfunction/model/ directory to see if there's really anything there and if the name is correct? Does your table in the DB have an "import_" prefix and not "import_modx_".
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 19980 ☆ A M B ☆
                • 275 Posts
                Hi Bob, thanks for reply.

                not sure if addPackage fails as I see neither 'failed to add package' nor 'added Package'

                >>> Did you check the core/components/certsfunction/model/ directory to see if there's really anything there and if the name is correct?
                --I think so, I attach the screenshots of the model and schema dirs. The listing of scheme XML is in the prev post under 'The createxpdoclasses code created the XML ' title.

                >>> Does your table in the DB have an "import_" prefix and not "import_modx_".
                --yes, it's my imported table from old website which I try to port to MODX now. The 'certs' table with 'import_' prefix contains the data that I need to operate with (I am going to import it to the MODX Resources)
                  modx and ecommerce pro
                  • 19980 ☆ A M B ☆
                  • 275 Posts
                  oops looks like the screenshots to the prev post did not really attache, here they are:https://plus.google.com/photos/109498197448404992305/albums/5695872068858364977?authkey=CNnMo7PJv-uMwgE [ed. note: modx.customize last edited this post 14 years, 9 months ago.]
                    modx and ecommerce pro
                    • 19980 ☆ A M B ☆
                    • 275 Posts
                    I am afraid there might be a problem with capital 'C' in this :
                    $CERT = $modx->getCollection('Certs'); 
                    
                      modx and ecommerce pro
                      • 3749
                      • 24,544 Posts
                      The fact that you don't get a success or failure message suggests that something is going wrong inside the addPackage() function. Anything in the MODX error log (Reports -> Error Log).?

                      I don't think the capital C should be a problem. I wonder if you need to call your class modCerts (though I don't know why you would need to do that). [ed. note: BobRay last edited this post 14 years, 9 months ago.]
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting