We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    there was a bug in the save - function, altered it above

    solution for the nested grid later
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 24676
      • 60 Posts
      Thanks Bruno - I can get somewhere with displaying the applications grid but not with the join table you gave me the solution for earlier.

      I look forward to your answer!
        • 4172
        • 5,888 Posts
        with this solution, you don't need the listbox anymore and you should remove it, because you would override the changes, you made within the nested grid.

        the productinfo - setup looks like that:

        {
          "formtabs":[
            {
              "MIGX_id":26,
              "caption":"product",
              "print_before_tabs":"0",
              "fields":[
                {
                  "MIGX_id":180,
                  "field":"name",
                  "caption":"Name",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"",
                  "inputOptionValues":"",
                  "default":"",
                  "pos":2
                }
              ],
              "pos":1
            },
            {
              "MIGX_id":28,
              "caption":"Applications",
              "print_before_tabs":"0",
              "fields":[
                {
                  "MIGX_id":184,
                  "field":"applicationsgrid",
                  "caption":"Applications",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"migxdb",
                  "validation":"",
                  "configs":"migxproductApplication",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"",
                  "inputOptionValues":"",
                  "default":"",
                  "pos":1
                }
              ],
              "pos":2
            }
          ],
          "contextmenus":"update||remove",
          "actionbuttons":"addItem",
          "columnbuttons":"",
          "filters":"",
          "extended":{
            "migx_add":"",
            "formcaption":"",
            "update_win_title":"",
            "win_id":"migxproducts",
            "maxRecords":"",
            "addNewItemAt":"bottom",
            "multiple_formtabs":"",
            "actionbuttonsperrow":4,
            "winbuttonslist":"",
            "extrahandlers":"",
            "filtersperrow":4,
            "packageName":"migxproducts",
            "classname":"ProductInfo",
            "task":"migxproducts",
            "getlistsort":"",
            "getlistsortdir":"",
            "use_custom_prefix":"0",
            "prefix":"",
            "grid":"",
            "gridload_mode":1,
            "check_resid":1,
            "check_resid_TV":"",
            "join_alias":"",
            "has_jointable":"yes",
            "getlistwhere":"",
            "joins":"",
            "cmpmaincaption":"",
            "cmptabcaption":"",
            "cmptabdescription":"",
            "cmptabcontroller":"",
            "winbuttons":"",
            "onsubmitsuccess":"",
            "submitparams":""
          },
          "columns":[
            {
              "MIGX_id":1,
              "header":"ID",
              "dataIndex":"id",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":""
            },
            {
              "MIGX_id":2,
              "header":"Name",
              "dataIndex":"name",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":""
            }
          ]
        }
        


        the setup for migxproductApplication

        {
          "formtabs":[
            {
              "MIGX_id":27,
              "caption":"product",
              "print_before_tabs":"0",
              "fields":[
                {
                  "MIGX_id":181,
                  "field":"application",
                  "caption":"Application",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"",
                  "inputOptionValues":"",
                  "default":"",
                  "pos":1
                }
              ],
              "pos":1
            }
          ],
          "contextmenus":"update||remove",
          "actionbuttons":"addItem",
          "columnbuttons":"",
          "filters":"",
          "extended":{
            "migx_add":"",
            "formcaption":"",
            "update_win_title":"",
            "win_id":"migxproductsApplication",
            "maxRecords":"",
            "addNewItemAt":"bottom",
            "multiple_formtabs":"",
            "actionbuttonsperrow":4,
            "winbuttonslist":"",
            "extrahandlers":"this.activateObject||this.deactivateObject",
            "filtersperrow":4,
            "packageName":"migxproducts",
            "classname":"Application",
            "task":"productsapplications",
            "getlistsort":"",
            "getlistsortdir":"",
            "use_custom_prefix":"0",
            "prefix":"",
            "grid":"",
            "gridload_mode":2,
            "check_resid":"0",
            "check_resid_TV":"",
            "join_alias":"",
            "has_jointable":"yes",
            "getlistwhere":"",
            "joins":"",
            "cmpmaincaption":"",
            "cmptabcaption":"",
            "cmptabdescription":"",
            "cmptabcontroller":"",
            "winbuttons":"",
            "onsubmitsuccess":"",
            "submitparams":""
          },
          "columns":[
            {
              "MIGX_id":1,
              "header":"ID",
              "dataIndex":"id",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":""
            },
            {
              "MIGX_id":2,
              "header":"Name",
              "dataIndex":"application",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":""
            },
            {
              "MIGX_id":3,
              "header":"Active",
              "dataIndex":"ProductsApplication_active",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"this.renderSwitchStatusOptions",
              "clickaction":"switchOption",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":[
                {
                  "MIGX_id":1,
                  "name":"active",
                  "value":1,
                  "clickaction":"switchOption",
                  "handler":"this.deactivateObject",
                  "image":"assets\/components\/migx\/style\/images\/tick.png"
                },
                {
                  "MIGX_id":2,
                  "name":"inactive",
                  "value":"0",
                  "clickaction":"switchOption",
                  "handler":"this.activateObject",
                  "image":"assets\/components\/migx\/style\/images\/cross.png"
                }
              ]
            }
          ]
        }
        


        then I created a new file-folder

        core/components/migxproducts/processors/mgr/productsapplications/

        yours would be

        core/components/products/processors/mgr/productsapplications/

        with two files:

        activaterelation.php

        <?php
        
        if (empty($scriptProperties['object_id'])) {
        
            return $modx->error->failure($modx->lexicon('error'));
        
        }
        
        $config = $modx->migx->customconfigs;
        
        $prefix = $modx->getOption('prefix', $config, null);
        $packageName = $config['packageName'];
        
        $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
        $modelpath = $packagepath . 'model/';
        
        $modx->addPackage($packageName, $modelpath, $prefix);
        $classname = $config['classname'];
        
        //$joinalias = isset($config['join_alias']) ? $config['join_alias'] : '';
        $joinclass = 'ProductApplication';
        
        if ($modx->lexicon) {
            $modx->lexicon->load($packageName . ':default');
        }
        
        $product_id = $modx->getOption('co_id',$scriptProperties,0);
        $application_id = $modx->getOption('object_id',$scriptProperties,0);
        
        switch ($scriptProperties['task']) {
            case 'activate':
                if ($joinobject = $modx->getObject($joinclass, array('product' => $product_id, 'application' => $application_id))) {
        
                } else {
                    $joinobject = $modx->newObject($joinclass);
                    $joinobject->set('product', $product_id);
                    $joinobject->set('application', $application_id);
                }
                $joinobject->save();
                break;
            case 'deactivate':
                $c = $modx->newQuery($joinclass);
                $c->where(array('product' => $product_id, 'application' => $application_id));
            
                if ($collection = $modx->getCollection($joinclass, $c)) {
                    foreach ($collection as $joinobject){
                        $joinobject->remove();
                    }
                }
                break;
            default:
                break;
        }
        
        
        //clear cache for all contexts
        /*
        $collection = $modx->getCollection('modContext');
        foreach ($collection as $context) {
            $contexts[] = $context->get('key');
        }
        $modx->cacheManager->refresh(array(
            'db' => array(),
            'auto_publish' => array('contexts' => $contexts),
            'context_settings' => array('contexts' => $contexts),
            'resource' => array('contexts' => $contexts),
            ));
        */
        return $modx->error->success();
        
        ?>
        


        and

        getlist.php

        <?php
        
        //if (!$modx->hasPermission('quip.thread_list')) return $modx->error->failure($modx->lexicon('access_denied'));
        
        $config = $modx->migx->customconfigs;
        
        $prefix = isset($config['prefix']) && !empty($config['prefix']) ? $config['prefix'] : null;
        if (isset($config['use_custom_prefix']) && !empty($config['use_custom_prefix'])) {
            $prefix = isset($config['prefix']) ? $config['prefix'] : '';
        }
        
        $checkdeleted = isset($config['gridactionbuttons']['toggletrash']['active']) && !empty($config['gridactionbuttons']['toggletrash']['active']) ? true : false;
        
        if (!empty($config['packageName'])) {
            $packageNames = explode(',', $config['packageName']);
            //all packages must have the same prefix for now!
            foreach ($packageNames as $packageName) {
                $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
                $modelpath = $packagepath . 'model/';
                if (is_dir($modelpath)){
                    $modx->addPackage($packageName, $modelpath, $prefix);
                } 
                
            }
        }
        
        $classname = $config['classname'];
        
        $product_id = $modx->getOption('object_id', $scriptProperties, '');
        $joins = '[{"alias":"ProductsApplication","on":"ProductsApplication.application=Application.id AND ProductsApplication.product='.$product_id.'"}]';
        $joins = $modx->fromJson($joins);
        
        $joinalias = isset($config['join_alias']) ? $config['join_alias'] : '';
        
        if (!empty($joinalias)) {
            if ($fkMeta = $modx->getFKDefinition($classname, $joinalias)) {
                $joinclass = $fkMeta['class'];
                $joinfield = $fkMeta[$fkMeta['owner']];
            } else {
                $joinalias = '';
            }
        }
        
        
        if ($modx->lexicon) {
            $modx->lexicon->load($packageName . ':default');
        }
        
        /* setup default properties */
        $isLimit = !empty($scriptProperties['limit']);
        $isCombo = !empty($scriptProperties['combo']);
        $start = $modx->getOption('start', $scriptProperties, 0);
        $limit = $modx->getOption('limit', $scriptProperties, 20);
        $sort = !empty($config['getlistsort']) ? $config['getlistsort'] : 'id';
        $sort = $modx->getOption('sort', $scriptProperties, $sort);
        $dir = !empty($config['getlistsortdir']) ? $config['getlistsortdir'] : 'ASC';
        $dir = $modx->getOption('dir', $scriptProperties, $dir);
        $showtrash = $modx->getOption('showtrash', $scriptProperties, '');
        $object_id = $modx->getOption('object_id', $scriptProperties, '');
        $resource_id = $modx->getOption('resource_id', $scriptProperties, is_object($modx->resource) ? $modx->resource->get('id') : false);
        $resource_id = !empty($object_id) ? $object_id : $resource_id;
        
        if (isset($sortConfig)) {
            $sort = '';
        }
        
        $where = !empty($config['getlistwhere']) ? $config['getlistwhere'] : '';
        $where = $modx->getOption('where', $scriptProperties, $where);
        
        $c = $modx->newQuery($classname);
        $c->select($modx->getSelectColumns($classname, $classname));
        
        if (!empty($joinalias)) {
            /*
            if ($joinFkMeta = $modx->getFKDefinition($joinclass, 'Resource')){
            $localkey = $joinFkMeta['local'];
            }    
            */
            $c->leftjoin($joinclass, $joinalias);
            $c->select($modx->getSelectColumns($joinclass, $joinalias, 'Joined_'));
        }
        
        if ($joins) {
            $modx->migx->prepareJoins($classname, $joins, $c);
        }
        
        /*
        $c->leftjoin('poProduktFormat','ProduktFormat', 'format_id = poFormat.id AND product_id ='.$scriptProperties['object_id']);
        //$c->select($classname.'.*');
        
        $c->select('ProduktFormat.format_id,ProduktFormat.calctype,ProduktFormat.price,ProduktFormat.published AS pof_published');
        */
        
        //print_r($config['gridfilters']);
        
        if (isset($config['gridfilters']) && count($config['gridfilters']) > 0) {
            foreach ($config['gridfilters'] as $filter) {
        
                if (!empty($filter['getlistwhere'])) {
        
                    $requestvalue = $modx->getOption($filter['name'], $scriptProperties, 'all');
                    
                    if (isset($scriptProperties[$filter['name']]) && $requestvalue != 'all') {
                        
                        $chunk = $modx->newObject('modChunk');
                        $chunk->setCacheable(false);
                        $chunk->setContent($filter['getlistwhere']);
                        $fwhere = $chunk->process($scriptProperties);
                        $fwhere = strpos($fwhere, '{') === 0 ? $modx->fromJson($fwhere) : $fwhere;
        
                        $c->where($fwhere);
                    }
                }
            }
        }
        
        
        if ($modx->migx->checkForConnectedResource($resource_id, $config)) {
            if (!empty($joinalias)) {
                $c->where(array($joinalias . '.' . $joinfield => $resource_id));
            } else {
                $c->where(array($classname . '.resource_id' => $resource_id));
            }
        }
        
        if ($checkdeleted) {
            if (!empty($showtrash)) {
                $c->where(array($classname . '.deleted' => '1'));
            } else {
                $c->where(array($classname . '.deleted' => '0'));
            }
        }
        
        if (!empty($where)) {
            $c->where($modx->fromJson($where));
        }
        
        $count = $modx->getCount($classname, $c);
        
        if (empty($sort)) {
            if (is_array($sortConfig)) {
                foreach ($sortConfig as $sort) {
                    $sortby = $sort['sortby'];
                    $sortdir = isset($sort['sortdir']) ? $sort['sortdir'] : 'ASC';
                    $c->sortby($sortby, $sortdir);
                }
            }
        
        
        } else {
            $c->sortby($sort, $dir);
        }
        if ($isCombo || $isLimit) {
            $c->limit($limit, $start);
        }
        //$c->sortby($sort,$dir);
        //$c->prepare();echo $c->toSql();
        $rows = array();
        if ($collection = $modx->getCollection($classname, $c)) {
            $pk = $modx->getPK($classname);
            foreach ($collection as $object) {
                $row = $object->toArray();
                $row['ProductsApplication_active'] = !empty($row['ProductsApplication_id']) ? 1 : 0;   
                $row['id'] = !isset($row['id']) ? $row[$pk] : $row['id'];
                $rows[] = $row;
            }
        }
        
        
        $rows = $modx->migx->checkRenderOptions($rows);
        


        This should show the grid with all Applications and a new column named 'Active'

        You can click into this column to active/deactivate the relation between the current product and the applications

          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 24676
          • 60 Posts
          Its works Brilliantly!! I am going to need to extend this now to work with more relationships. I need to go through them in a bit more detail - but can you give some explanation on what activaterelation.php and getlist.php are doing in this case?

          Again - thank you so much - such speedy responses!
            • 4172
            • 5,888 Posts
            the getlist.php is a bit modified copy of
            https://github.com/Bruno17/MIGX/blob/master/core/components/migx/processors/mgr/default/getlist.php

            modfied parts are:

            //join all applications with the currently edited product
            $product_id = $modx->getOption('object_id', $scriptProperties, '');
            $joins = '[{"alias":"ProductsApplication","on":"ProductsApplication.application=Application.id AND ProductsApplication.product='.$product_id.'"}]';
            $joins = $modx->fromJson($joins);
            


            and

                    //add the field ProductsApplication_active, if there is a joined application found
                    $row = $object->toArray();
                    $row['ProductsApplication_active'] = !empty($row['ProductsApplication_id']) ? 1 : 0; 
            


            the activaterelation.php, well, it does add or remove a connection.

            If you want to have it reusable you could change the getlist.php like:

            <?php
            
            //if (!$modx->hasPermission('quip.thread_list')) return $modx->error->failure($modx->lexicon('access_denied'));
            
            $config = $modx->migx->customconfigs;
            
            $prefix = isset($config['prefix']) && !empty($config['prefix']) ? $config['prefix'] : null;
            if (isset($config['use_custom_prefix']) && !empty($config['use_custom_prefix'])) {
                $prefix = isset($config['prefix']) ? $config['prefix'] : '';
            }
            
            $checkdeleted = isset($config['gridactionbuttons']['toggletrash']['active']) && !empty($config['gridactionbuttons']['toggletrash']['active']) ? true : false;
            
            if (!empty($config['packageName'])) {
                $packageNames = explode(',', $config['packageName']);
                //all packages must have the same prefix for now!
                foreach ($packageNames as $packageName) {
                    $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
                    $modelpath = $packagepath . 'model/';
                    if (is_dir($modelpath)) {
                        $modx->addPackage($packageName, $modelpath, $prefix);
                    }
            
                }
            }
            
            $classname = $config['classname'];
            
            //join all applications with the currently edited product
            $joinalias = isset($config['join_alias']) ? $config['join_alias'] : '';
            
            $joinconfig = $modx->fromJson($joinalias);
            
            $joinclass = $modx->getOption('classname', $joinconfig, '');
            $local = $modx->getOption('local', $joinconfig, '');
            $foreign = $modx->getOption('foreign', $joinconfig, '');
            
            $object_id = $modx->getOption('object_id', $scriptProperties, '');
            $joins = '[{"alias":"Joined","classname":"' . $joinclass . '","on":"Joined.' . $foreign . '=' . $classname . '.id AND Joined.' . $local . '=' . $object_id . '"}]';
            $joins = $modx->fromJson($joins);
            
            
            if ($modx->lexicon) {
                $modx->lexicon->load($packageName . ':default');
            }
            
            /* setup default properties */
            $isLimit = !empty($scriptProperties['limit']);
            $isCombo = !empty($scriptProperties['combo']);
            $start = $modx->getOption('start', $scriptProperties, 0);
            $limit = $modx->getOption('limit', $scriptProperties, 20);
            $sort = !empty($config['getlistsort']) ? $config['getlistsort'] : 'id';
            $sort = $modx->getOption('sort', $scriptProperties, $sort);
            $dir = !empty($config['getlistsortdir']) ? $config['getlistsortdir'] : 'ASC';
            $dir = $modx->getOption('dir', $scriptProperties, $dir);
            $showtrash = $modx->getOption('showtrash', $scriptProperties, '');
            $object_id = $modx->getOption('object_id', $scriptProperties, '');
            $resource_id = $modx->getOption('resource_id', $scriptProperties, is_object($modx->resource) ? $modx->resource->get('id') : false);
            $resource_id = !empty($object_id) ? $object_id : $resource_id;
            
            if (isset($sortConfig)) {
                $sort = '';
            }
            
            $where = !empty($config['getlistwhere']) ? $config['getlistwhere'] : '';
            $where = $modx->getOption('where', $scriptProperties, $where);
            
            $c = $modx->newQuery($classname);
            $c->select($modx->getSelectColumns($classname, $classname));
            
            
            if ($joins) {
                $modx->migx->prepareJoins($classname, $joins, $c);
            }
            
            if (isset($config['gridfilters']) && count($config['gridfilters']) > 0) {
                foreach ($config['gridfilters'] as $filter) {
            
                    if (!empty($filter['getlistwhere'])) {
            
                        $requestvalue = $modx->getOption($filter['name'], $scriptProperties, 'all');
            
                        if (isset($scriptProperties[$filter['name']]) && $requestvalue != 'all') {
            
                            $chunk = $modx->newObject('modChunk');
                            $chunk->setCacheable(false);
                            $chunk->setContent($filter['getlistwhere']);
                            $fwhere = $chunk->process($scriptProperties);
                            $fwhere = strpos($fwhere, '{') === 0 ? $modx->fromJson($fwhere) : $fwhere;
            
                            $c->where($fwhere);
                        }
                    }
                }
            }
            
            
            if ($checkdeleted) {
                if (!empty($showtrash)) {
                    $c->where(array($classname . '.deleted' => '1'));
                } else {
                    $c->where(array($classname . '.deleted' => '0'));
                }
            }
            
            if (!empty($where)) {
                $c->where($modx->fromJson($where));
            }
            
            $count = $modx->getCount($classname, $c);
            
            if (empty($sort)) {
                if (is_array($sortConfig)) {
                    foreach ($sortConfig as $sort) {
                        $sortby = $sort['sortby'];
                        $sortdir = isset($sort['sortdir']) ? $sort['sortdir'] : 'ASC';
                        $c->sortby($sortby, $sortdir);
                    }
                }
            
            
            } else {
                $c->sortby($sort, $dir);
            }
            if ($isCombo || $isLimit) {
                $c->limit($limit, $start);
            }
            //$c->sortby($sort,$dir);
            //$c->prepare();echo $c->toSql();
            $rows = array();
            if ($collection = $modx->getCollection($classname, $c)) {
                $pk = $modx->getPK($classname);
                foreach ($collection as $object) {
                    $row = $object->toArray();
                    $row['Joined_active'] = !empty($row['Joined_id']) ? 1 : 0;
                    $row['id'] = !isset($row['id']) ? $row[$pk] : $row['id'];
                    $rows[] = $row;
                }
            }
            
            
            $rows = $modx->migx->checkRenderOptions($rows);
            ?>
            


            and the activaterelation.php to

            <?php
            
            if (empty($scriptProperties['object_id'])) {
            
                return $modx->error->failure($modx->lexicon('error'));
            
            }
            
            $config = $modx->migx->customconfigs;
            
            $prefix = $modx->getOption('prefix', $config, null);
            $packageName = $config['packageName'];
            
            $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
            $modelpath = $packagepath . 'model/';
            
            $modx->addPackage($packageName, $modelpath, $prefix);
            $classname = $config['classname'];
            
            //$joinalias = '{"classname":"ProductApplication","local":"product","foreign":"application"}';
            $joinalias = isset($config['join_alias']) ? $config['join_alias'] : '';
            
            $joinconfig = $modx->fromJson($joinalias);
            
            $joinclass = $modx->getOption('classname',$joinconfig,'');
            $local = $modx->getOption('local',$joinconfig,'');
            $foreign = $modx->getOption('foreign',$joinconfig,'');
            
            if ($modx->lexicon) {
                $modx->lexicon->load($packageName . ':default');
            }
            
            $product_id = $modx->getOption('co_id',$scriptProperties,0);
            $application_id = $modx->getOption('object_id',$scriptProperties,0);
            
            switch ($scriptProperties['task']) {
                case 'activate':
                    if ($joinobject = $modx->getObject($joinclass, array($local => $product_id, $foreign => $application_id))) {
            
                    } else {
                        $joinobject = $modx->newObject($joinclass);
                        $joinobject->set($local, $product_id);
                        $joinobject->set($foreign, $application_id);
                    }
                    $joinobject->save();
                    break;
                case 'deactivate':
                    $c = $modx->newQuery($joinclass);
                    $c->where(array($local => $product_id, $foreign => $application_id));
                
                    if ($collection = $modx->getCollection($joinclass, $c)) {
                        foreach ($collection as $joinobject){
                            $joinobject->remove();
                        }
                    }
                    break;
                default:
                    break;
            }
            
            
            //clear cache for all contexts
            /*
            $collection = $modx->getCollection('modContext');
            foreach ($collection as $context) {
                $contexts[] = $context->get('key');
            }
            $modx->cacheManager->refresh(array(
                'db' => array(),
                'auto_publish' => array('contexts' => $contexts),
                'context_settings' => array('contexts' => $contexts),
                'resource' => array('contexts' => $contexts),
                ));
            */
            return $modx->error->success();
            
            ?>
            



            and put this into the now unused field 'Join Alias' of the MIGXdb - configuration

            {"classname":"ProductApplication","local":"product","foreign":"application"}
            


            and change the fieldname of the grid - column to
            Joined_active
            
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 4172
              • 5,888 Posts
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 24676
                • 60 Posts
                Bruno - That's awesome. I will let you know how I get on!
                  • 48532
                  • 23 Posts
                  Hey together.

                  First of all thanks Bruno for that impressive tool! Slowly but steady I manage to reveal the whole magic of it – thanks to threads like this which fits perfectly situation.
                  Right now I am at the same point where rebornmedia has been before: I tried to create a many-to-many relation with a join-table (products, attributes, productAttributes) but can not manage to get the attributes displayed in the grid of my products. I can create attributes over the displayed grid, but they don't get listed.

                  Now that the reusable preprocessors are included:
                  1) Do I have to customize anything in the getlist.php or activaterelation.php? As far is I went through the code everything should be dynamically input over the config through Join-Alias field.
                  2) The local and foreign definition in the Join-Alias are referring to the according Classes?
                  {"classname":"ProductApplication","local":"product","foreign":"application"}


                  Maybe can somebody point out where I got on the wrong track smiley


                  Relevant part of the schema:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <model package="testproducts" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
                  	<object class="Products" table="products" extends="xPDOSimpleObject">
                  		<field key="name" dbtype="varchar" precision="45" phptype="string" null="true" />
                  		<field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
                  		<field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
                  		<field key="editedon" dbtype="datetime" phptype="datetime" null="true"/>
                  		<field key="editedby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
                  		<field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>
                  		<field key="deletedon" dbtype="datetime" phptype="datetime" null="false"/>
                  		<field key="deletedby" dbtype="int" precision="10" phptype="integer" null="false" default="0"/>
                  		<field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>
                  		<field key="publishedon" dbtype="datetime" phptype="datetime" null="false"/>
                  		<field key="publishedby" dbtype="int" precision="10" phptype="integer" null="false" default="0"/>
                  		
                  		<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/>
                  		<aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/>	
                  		<aggregate alias="PublishedBy" class="modUser" local="publishedby" foreign="id" cardinality="one" owner="foreign"/>
                  		
                  		<composite alias="ProductsAttributes" class="ProductsAttributes" local="id" foreign="product_id" cardinality="many" owner="local" />
                  		<composite alias="ProductsDescriptions" class="ProductsFiles" local="id" foreign="product_id" cardinality="many" owner="local" />
                  	</object>
                  
                  	<object class="Attributes" table="attributes" extends="xPDOSimpleObject">
                  		<field key="name" dbtype="varchar" precision="45" phptype="string" null="false" />
                  		<field key="type" dbtype="int" precision="11" phptype="integer" null="false" />
                  		
                  		<composite alias="ProductsAttributes" class="ProductsAttributes" local="id" foreign="attribute_id" cardinality="many" owner="local" />
                  		<composite alias="AttributesDescriptions" class="AttributesDescriptions" local="id" foreign="attribute_id" cardinality="many" owner="local" />
                  	</object>
                  	
                  	
                  	<object class="ProductsAttributes" table="products_attributes" extends="xPDOSimpleObject">
                  		<field key="product_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" />
                  		<field key="attribute_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" />
                  		
                  		<aggregate alias="Products" class="Products" local="product_id" foreign="id" cardinality="one" owner="foreign" />
                  		<aggregate alias="Attributes" class="Attributes" local="attribute_id" foreign="id" cardinality="one" owner="foreign" />
                  	</object>
                  	
                  	
                  	(…)
                  	
                  </model>
                  



                  migx config for "products"
                  {
                    "formtabs":[
                      {
                        "MIGX_id":3,
                        "caption":"my product",
                        "print_before_tabs":"0",
                        "fields":[
                          {
                            "MIGX_id":6,
                            "field":"name",
                            "caption":"Product Name",
                            "description":"",
                            "description_is_code":"0",
                            "inputTV":"",
                            "inputTVtype":"",
                            "validation":"",
                            "configs":"",
                            "restrictive_condition":"",
                            "display":"",
                            "sourceFrom":"config",
                            "sources":"",
                            "inputOptionValues":"",
                            "default":"",
                            "pos":1
                          },
                          {
                            "MIGX_id":8,
                            "field":"published",
                            "caption":"Publish",
                            "description":"",
                            "description_is_code":"0",
                            "inputTV":"",
                            "inputTVtype":"checkbox",
                            "validation":"",
                            "configs":"",
                            "restrictive_condition":"",
                            "display":"",
                            "sourceFrom":"config",
                            "sources":"",
                            "inputOptionValues":"yes==1",
                            "default":"0",
                            "pos":2
                          },
                          {
                            "MIGX_id":14,
                            "field":"attributes",
                            "caption":"Attribute",
                            "description":"",
                            "description_is_code":"0",
                            "inputTV":"",
                            "inputTVtype":"migxdb",
                            "validation":"",
                            "configs":"attributes",
                            "restrictive_condition":"",
                            "display":"",
                            "sourceFrom":"config",
                            "sources":"",
                            "inputOptionValues":"",
                            "default":"",
                            "pos":3
                          }
                        ],
                        "pos":1
                      }
                    ],
                    "contextmenus":"update||duplicate||publish||unpublish||remove",
                    "actionbuttons":"addItem||bulk",
                    "columnbuttons":"update||duplicate||publish||unpublish||remove",
                    "filters":"",
                    "extended":{
                      "migx_add":"Neues Produkt einstellen",
                      "disable_add_item":"",
                      "formcaption":"Form Caption here",
                      "update_win_title":"This is the window title",
                      "win_id":"products",
                      "maxRecords":"",
                      "addNewItemAt":"bottom",
                      "multiple_formtabs":"",
                      "actionbuttonsperrow":4,
                      "winbuttonslist":"",
                      "extrahandlers":"",
                      "filtersperrow":4,
                      "packageName":"viacortest",
                      "classname":"Products",
                      "task":"",
                      "getlistsort":"",
                      "getlistsortdir":"",
                      "sortconfig":"",
                      "gridpagesize":"",
                      "use_custom_prefix":1,
                      "prefix":"vt_",
                      "grid":"",
                      "gridload_mode":1,
                      "check_resid":1,
                      "check_resid_TV":"",
                      "join_alias":{
                        "classname":"ProductsAttributes",
                        "local":"products",
                        "foreign":"attributes"
                      },
                      "has_jointable":"yes",
                      "getlistwhere":"",
                      "joins":"",
                      "cmpmaincaption":"Products",
                      "cmptabcaption":"Editieren",
                      "cmptabdescription":"Meine Erkl\u00e4rung",
                      "cmptabcontroller":"",
                      "winbuttons":"",
                      "onsubmitsuccess":"",
                      "submitparams":""
                    },
                    "columns":[
                      {
                        "MIGX_id":1,
                        "header":"ID",
                        "dataIndex":"id",
                        "width":"",
                        "sortable":"false",
                        "show_in_grid":1,
                        "renderer":"",
                        "clickaction":"",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":""
                      },
                      {
                        "MIGX_id":2,
                        "header":"Name",
                        "dataIndex":"name",
                        "width":"",
                        "sortable":"false",
                        "show_in_grid":1,
                        "renderer":"",
                        "clickaction":"",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":""
                      },
                      {
                        "MIGX_id":5,
                        "header":"Created",
                        "dataIndex":"createdon",
                        "width":"",
                        "sortable":"false",
                        "show_in_grid":1,
                        "renderer":"this.renderDate",
                        "clickaction":"",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":""
                      },
                      {
                        "MIGX_id":6,
                        "header":"Last Edited by",
                        "dataIndex":"editedby",
                        "width":"",
                        "sortable":"false",
                        "show_in_grid":1,
                        "renderer":"",
                        "clickaction":"",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":""
                      },
                      {
                        "MIGX_id":3,
                        "header":"Published",
                        "dataIndex":"published",
                        "width":"",
                        "sortable":"false",
                        "show_in_grid":1,
                        "renderer":"this.renderCrossTick",
                        "clickaction":"",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":""
                      }
                    ]
                  }
                  



                  migx config for "attributes"
                  {
                    "formtabs":[
                      {
                        "MIGX_id":4,
                        "caption":"formtab_basic",
                        "print_before_tabs":"0",
                        "fields":[
                          {
                            "MIGX_id":11,
                            "field":"name",
                            "caption":"name",
                            "description":"",
                            "description_is_code":"0",
                            "inputTV":"",
                            "inputTVtype":"",
                            "validation":"",
                            "configs":"",
                            "restrictive_condition":"",
                            "display":"",
                            "sourceFrom":"config",
                            "sources":"",
                            "inputOptionValues":"",
                            "default":"",
                            "pos":1
                          },
                          {
                            "MIGX_id":12,
                            "field":"type",
                            "caption":"type",
                            "description":"",
                            "description_is_code":"0",
                            "inputTV":"",
                            "inputTVtype":"listbox",
                            "validation":"",
                            "configs":"test1\ntest2",
                            "restrictive_condition":"",
                            "display":"",
                            "sourceFrom":"config",
                            "sources":"",
                            "inputOptionValues":"Product==1 || System==2",
                            "default":"",
                            "pos":2
                          }
                        ],
                        "pos":1
                      }
                    ],
                    "contextmenus":"update||duplicate||publish||unpublish||remove",
                    "actionbuttons":"addItem",
                    "columnbuttons":"update||duplicate||publish||unpublish||remove",
                    "filters":"",
                    "extended":{
                      "migx_add":"",
                      "disable_add_item":"",
                      "formcaption":"",
                      "update_win_title":"",
                      "win_id":"attributes",
                      "maxRecords":"",
                      "addNewItemAt":"bottom",
                      "multiple_formtabs":"",
                      "actionbuttonsperrow":4,
                      "winbuttonslist":"",
                      "extrahandlers":"",
                      "filtersperrow":4,
                      "packageName":"viacortest",
                      "classname":"Attributes",
                      "task":"",
                      "getlistsort":"",
                      "getlistsortdir":"",
                      "sortconfig":"",
                      "gridpagesize":"",
                      "use_custom_prefix":1,
                      "prefix":"vt_",
                      "grid":"",
                      "gridload_mode":1,
                      "check_resid":1,
                      "check_resid_TV":"",
                      "join_alias":"",
                      "has_jointable":"yes",
                      "getlistwhere":"",
                      "joins":"",
                      "cmpmaincaption":"",
                      "cmptabcaption":"",
                      "cmptabdescription":"",
                      "cmptabcontroller":"",
                      "winbuttons":"",
                      "onsubmitsuccess":"",
                      "submitparams":""
                    },
                    "columns":[
                      {
                        "MIGX_id":1,
                        "header":"id",
                        "dataIndex":"id",
                        "width":"",
                        "sortable":"false",
                        "show_in_grid":1,
                        "renderer":"",
                        "clickaction":"",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":""
                      },
                      {
                        "MIGX_id":2,
                        "header":"name",
                        "dataIndex":"name",
                        "width":"",
                        "sortable":"false",
                        "show_in_grid":1,
                        "renderer":"",
                        "clickaction":"",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":""
                      },
                      {
                        "MIGX_id":3,
                        "header":"type",
                        "dataIndex":"type",
                        "width":"",
                        "sortable":true,
                        "show_in_grid":1,
                        "renderer":"",
                        "clickaction":"",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":""
                      },
                      {
                        "MIGX_id":4,
                        "header":"Product Attributes Activation",
                        "dataIndex":"Join_active",
                        "width":"",
                        "sortable":"false",
                        "show_in_grid":1,
                        "renderer":"this.renderSwitchStatusOptions",
                        "clickaction":"switchOption",
                        "selectorconfig":"",
                        "renderchunktpl":"",
                        "renderoptions":[
                          {
                            "MIGX_id":1,
                            "name":"activate",
                            "value":1,
                            "clickaction":"switchOption",
                            "handler":"this.deactivateObject",
                            "image":"assets\/components\/migx\/style\/images\/tick.png"
                          },
                          {
                            "MIGX_id":2,
                            "name":"deactivate",
                            "value":"0",
                            "clickaction":"switchOption",
                            "handler":"this.activateObject",
                            "image":"assets\/components\/migx\/style\/images\/cross.png"
                          }
                        ]
                      }
                    ]
                  }



                  And if helpful, part of the error-log.
                  When opening/loading one Product:
                  (ERROR @ /assets/components/migx/connector.php) No foreign key definition for parentClass: Products using relation alias: "classname":"ProductsAttributes","local":"products","foreign":"attributes"
                  


                  When loading the grid inside a product
                   (ERROR @ /assets/components/migx/connector.php) Error 42S22 executing statement: 
                  Array
                  (
                      [0] => 42S22
                      [1] => 1054
                      [2] => Unknown column 'Attributes.resource_id' in 'where clause'
                  )
                  
                    • 4172
                    • 5,888 Posts
                    try to set the setting

                    "has_jointable":"yes",

                    to "no" (tab MIGXdb - settings)
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 48532
                      • 23 Posts
                      Thanks Bruno, already tested that earlier. No change in the behavior. Error-Log also comes up again with those two issues. I just can not come across where I could have went wrong … The class names in the join-alias config are correct?