We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11055 ☆ A M B ☆
    • 3,112 Posts
    Hi guys,
    I have a problem when I tried to delete a record.
    schema:
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="myPackage" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
        <object class="Categories" table="categories" extends="xPDOSimpleObject">
            <field key="parent_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
            <field key="sort_order" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
    
            <index alias="parent_id" name="parent_id" primary="false" unique="false" type="BTREE" >
                <column key="parent_id" length="" collation="A" null="false" />
            </index>
    
            <composite alias="Langs" class="CategoriesLang" local="id" foreign="cat_id" cardinality="many" owner="local" />
        </object>
        <object class="CategoriesLang" table="categories_lang" extends="xPDOObject">
            <field key="cat_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" index="index" />
            <field key="lang_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" index="index" />
            <field key="name" dbtype="varchar" precision="50" phptype="string" null="true" />
            <field key="description" dbtype="text" phptype="string" null="true" />
    
            <index alias="cat_id" name="cat_id" primary="false" unique="false" type="BTREE" >
                <column key="cat_id" length="" collation="A" null="false" />
            </index>
            <index alias="lang_id" name="lang_id" primary="false" unique="false" type="BTREE" >
                <column key="lang_id" length="" collation="A" null="false" />
            </index>
    
            <aggregate alias="Category" class="Categories" local="cat_id" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="Langs" class="Langs" local="lang_id" foreign="id" cardinality="many" owner="foreign" />
        </object>
    </model>
    

    The CategoriesLang object is an intermediate table between the Category and Language, so I didn't set up any primary key.
    Processor:
    <?php
    class myPackageCatalogCategoriesDeleteProcessor extends modObjectRemoveProcessor {
    
        public $primaryKeyField = 'id';
        public $classKey = 'Categories';
    
        /**
         * Log the removal manager action
         * @return void
         */
        public function logManagerAction() {
    
        }
    
    }
    
    return 'myPackageCatalogCategoriesDeleteProcessor ';
    

    The category was deleted, but the dependent language entries were not.
    Error:
    [2012-07-17 09:12:32] (ERROR @ /mysite/assets/components/mypackage/connector.php) Error removing dependent object: Array
    (
        [cat_id] => 6
        [lang_id] => 1
        [name] => New Category
        [description] => 
    )
    
    [2012-07-17 09:12:32] (ERROR @ /mysite/assets/components/mypackage/connector.php) Error removing dependent object: Array
    (
        [cat_id] => 6
        [lang_id] => 2
        [name] => Nouvelle Catégorie
        [description] => 
    )
    

    What am I missing here?

    TIA,
    Rico

    This question has been answered by opengeek. See the first response.

      Rico
      Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
      MODx is great, but knowing how to use it well makes it perfect!

      www.virtudraft.com

      Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

      Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

      Maintainter/contributor of Babel

      Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
    • discuss.answer
      • 22303 MODX Staff
      • 10,725 Posts
      You have to define a primary key, even if it is just the aggregation of two or more foreign keys. In this case the primary key should be cat_id + lang_id.
        • 11055 ☆ A M B ☆
        • 3,112 Posts
        haaa...
        the joint primary keys.

        understood.
        thx, jason
          Rico
          Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
          MODx is great, but knowing how to use it well makes it perfect!

          www.virtudraft.com

          Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

          Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

          Maintainter/contributor of Babel

          Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.