We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50593
    • 19 Posts
    Hello, I'm studying MIGX and currently trying to reproduce k_hansen's databases and CMPs from this topic: https://forums.modx.com/thread/96409/help-with-simple-many-to-many-nested-migxdb-cmp

    k_hansen points out that one should use "the Join Alias field for the staff members table".

    He says:

    Once I made the change the staff member ID auto saved the staff members categories table correctly.

    But this seems to not be working for me. I tried to put [{"alias":"StaffMembers"}], {"alias":"StaffMembers"} and simply "StaffMembers" into my staff/categories CMP like this:

    {
      "formtabs":[
        {
          "MIGX_id":8,
          "caption":"Staff Categories",
          "print_before_tabs":"0",
          "fields":[
            {
              "MIGX_id":17,
              "field":"category_id",
              "caption":"Category",
              "description":"",
              "description_is_code":"0",
              "inputTV":"staff_categories",
              "inputTVtype":"",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":1
            }
          ],
          "pos":1
        }
      ],
      "contextmenus":"update||remove",
      "actionbuttons":"addItem",
      "columnbuttons":"update||remove",
      "filters":"",
      "extended":{
        "migx_add":"",
        "disable_add_item":"",
        "add_items_directly":"",
        "formcaption":"",
        "update_win_title":"",
        "win_id":"staff_member_categories",
        "maxRecords":"",
        "addNewItemAt":"bottom",
        "multiple_formtabs":"",
        "multiple_formtabs_label":"",
        "multiple_formtabs_field":"",
        "multiple_formtabs_optionstext":"",
        "multiple_formtabs_optionsvalue":"",
        "actionbuttonsperrow":4,
        "winbuttonslist":"",
        "extrahandlers":"",
        "filtersperrow":4,
        "packageName":"staff",
        "classname":"StaffMemberCategories",
        "task":"",
        "getlistsort":"",
        "getlistsortdir":"",
        "sortconfig":"",
        "gridpagesize":"",
        "use_custom_prefix":"0",
        "prefix":"",
        "grid":"",
        "gridload_mode":2,
        "check_resid":"0",
        "check_resid_TV":"",
        "join_alias":[
          {
            "alias":"StaffMembers"
          }
        ],
        "has_jointable":"no",
        "getlistwhere":"",
        "joins":[
          {
            "alias":"StaffCategories"
          }
        ],
        "hooksnippets":"",
        "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":"",
          "editor":""
        },
        {
          "MIGX_id":2,
          "header":"Staff ID",
          "dataIndex":"staff_id",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":3,
          "header":"Category ID",
          "dataIndex":"category_id",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":4,
          "header":"Staff Table ID",
          "dataIndex":"StaffMembers_id",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":5,
          "header":"Staff Name",
          "dataIndex":"StaffMembers_name",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":6,
          "header":"Category Name",
          "dataIndex":"StaffCategories_category",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        }
      ]
    }


    but it had no effect.

    So, please, explain me, what I'm doing wrong.

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

      • 4172
      • 5,888 Posts
      Is it this schema from the first post, which you are working with?
      https://forums.modx.com/thread/96409/help-with-simple-many-to-many-nested-migxdb-cmp#dis-post-521761
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 50593
        • 19 Posts
        Quote from: Bruno17 at Jun 10, 2015, 10:58 AM
        Is it this schema from the first post, which you are working with?
        https://forums.modx.com/thread/96409/help-with-simple-many-to-many-nested-migxdb-cmp#dis-post-521761

        Yes. I just copy-pasted both the schema and JSON from that topic.
        • discuss.answer
          • 4172
          • 5,888 Posts
          this should do it:

          {
            "formtabs":[
              {
                "MIGX_id":88,
                "caption":"Staff Categories",
                "print_before_tabs":"0",
                "fields":[
                  {
                    "MIGX_id":387,
                    "field":"category_id",
                    "caption":"Category",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"listbox",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"",
                    "inputOptionValues":"@EVAL return 'Select One==||' . $modx->runSnippet('migxLoopCollection',array('packageName'=>'staff','classname'=>'StaffCategory','tpl'=>'@CODE:[[+category]]==[[+id]]','outputSeparator'=>'||'));",
                    "default":"",
                    "useDefaultIfEmpty":"0",
                    "pos":1
                  }
                ],
                "pos":1
              }
            ],
            "contextmenus":"update||remove",
            "actionbuttons":"addItem",
            "columnbuttons":"update||remove",
            "filters":"",
            "extended":{
              "migx_add":"",
              "disable_add_item":"",
              "add_items_directly":"",
              "formcaption":"",
              "update_win_title":"",
              "win_id":"staff_member_categories",
              "maxRecords":"",
              "addNewItemAt":"bottom",
              "multiple_formtabs":"",
              "multiple_formtabs_label":"",
              "multiple_formtabs_field":"",
              "multiple_formtabs_optionstext":"",
              "multiple_formtabs_optionsvalue":"",
              "actionbuttonsperrow":4,
              "winbuttonslist":"",
              "extrahandlers":"",
              "filtersperrow":4,
              "packageName":"staff",
              "classname":"StaffMemberCategories",
              "task":"",
              "getlistsort":"",
              "getlistsortdir":"",
              "sortconfig":"",
              "gridpagesize":"",
              "use_custom_prefix":"0",
              "prefix":"",
              "grid":"",
              "gridload_mode":2,
              "check_resid":1,
              "check_resid_TV":"",
              "join_alias":"StaffMembers",
              "has_jointable":"no",
              "getlistwhere":"",
              "joins":[
                {
                  "alias":"StaffCategories"
                }
              ],
              "hooksnippets":{
                "aftersave":"staff_member_categories_aftersave"
              },
              "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":"",
                "editor":""
              },
              {
                "MIGX_id":2,
                "header":"Staff ID",
                "dataIndex":"staff_id",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"",
                "editor":""
              },
              {
                "MIGX_id":3,
                "header":"Category ID",
                "dataIndex":"category_id",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"",
                "editor":""
              },
              {
                "MIGX_id":4,
                "header":"Staff Table ID",
                "dataIndex":"Joined_id",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"",
                "editor":""
              },
              {
                "MIGX_id":5,
                "header":"Staff Name",
                "dataIndex":"Joined_name",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"",
                "editor":""
              },
              {
                "MIGX_id":6,
                "header":"Category Name",
                "dataIndex":"StaffCategories_category",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"",
                "editor":""
              }
            ]
          }
          


          this are the important settings:

              
              "check_resid":1,
              "join_alias":"StaffMembers",
              "has_jointable":"no",
              "joins":[
                {
                  "alias":"StaffCategories"
                }
              ],
              "hooksnippets":{
                "aftersave":"staff_member_categories_aftersave"
              },
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 50593
            • 19 Posts
            Quote from: Bruno17 at Jun 10, 2015, 01:22 PM
            this should do it:

            Yes, that did the trick. Thank you so much, Bruno! You've saved me so much time!

            But what does "check_resid" mean? And why do we need $postvalues and $configs variables in staff_member_categories_aftersave snippet?

              • 4172
              • 5,888 Posts
              But what does "check_resid" mean?

              If set, it does mainly three things:

              In the getlist-processor, filter by joinalias connected objects
              https://github.com/Bruno17/MIGX/blob/master/core/components/migx/processors/mgr/default/getlist.php#L128

              In the update-processor, it tries to set the joinfield with the id of the parent-object
              https://github.com/Bruno17/MIGX/blob/master/core/components/migx/processors/mgr/default/update.php#L102

              And it doesn't load the grid, as long, as it is on a unsaved(new) parent
              https://github.com/Bruno17/MIGX/blob/master/core/components/migx/elements/tv/migxdb.tpl#L73
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 4172
                • 5,888 Posts
                And why do we need $postvalues and $configs variables in staff_member_categories_aftersave snippet?

                They are not used in that case.
                I've added them only, to show, that they are availiable in the aftersave-hook-snippet.

                I'm even not sure, if this aftersave-hook-snippet is necessary at all, in that case, or if it wouldn't allready work with the joinalias/check_resid - settings alone.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 50593
                  • 19 Posts
                  Thank you for your reply, Bruno!

                  I have one more problem. k_hansen uses staff/categories table in the nested grid and I'd like to use categories table with a custom boolean field instead. This field should be represented as a checkbox, that is checked when there is a record in the staff/categories table with the corresponding staff_id and category_id in its fields and unchecked otherwise. Checking the checkbox should add the record and removing the checkbox should remove it.

                  I suspect, that this could be done with the help of connectors/processors, so where can I find information on processors programming?

                  I found this: http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/using-runprocessor but I didn't get the point. [ed. note: marshwiggle last edited this post 11 years, 4 months ago.]
                    • 4172
                    • 5,888 Posts
                    this would be much the same like this one:
                    https://github.com/Bruno17/migxResourceCategories

                    here is the configuration for the grid:
                    https://github.com/Bruno17/migxResourceCategories/blob/master/core/components/migxresourcecategories/migxconfigs/mrc_categoryresources.config.js

                    the stuff is done with the virtual 'joined' - column with the renderSwitchStatusOptions - renderer for that column
                    see also the renderoptions and the selected icon for each status.

                        {
                          "MIGX_id":3,
                          "header":"Joined",
                          "dataIndex":"joined",
                          "width":10,
                          "sortable":"false",
                          "show_in_grid":1,
                          "renderer":"this.renderSwitchStatusOptions",
                          "clickaction":"switchOption",
                          "selectorconfig":"",
                          "renderchunktpl":"",
                          "renderoptions":[
                            {
                              "MIGX_id":1,
                              "name":"joined",
                              "use_as_fallback":"",
                              "value":1,
                              "clickaction":"",
                              "handler":"",
                              "image":"assets\/components\/migx\/style\/images\/cb_ticked.png"
                            },
                            {
                              "MIGX_id":2,
                              "name":"unjoined",
                              "use_as_fallback":1,
                              "value":"0",
                              "clickaction":"",
                              "handler":"",
                              "image":"assets\/components\/migx\/style\/images\/cb_empty.png"
                            }
                          ],
                          "editor":""
                        },
                    


                    don't forget to check this extrahandler:

                    "extrahandlers":"this.handleColumnSwitch",


                    here is the custom-processor, which does the magic (creating/removing the join-object, when you click that column):
                    https://github.com/Bruno17/migxResourceCategories/blob/master/core/components/migxresourcecategories/processors/mgr/default/handlecolumnswitch.php

                    yours should be under:
                    core/components/{packagename}/processors/mgr/default/handlecolumnswitch.php

                    and some other custom-processors (copied from core/components/migx/processors/mgr/default/ with some extra lines of code)

                    https://github.com/Bruno17/migxResourceCategories/tree/master/core/components/migxresourcecategories/processors/mgr/resourcecategories)
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 50593
                      • 19 Posts
                      Wow! smiley Now it becomes more clear.

                      But what do
                      $scriptProperties['idx']

                      and
                      $modx->migx->customconfigs

                      variables from your handlecolumnswitch.php stand for? And what should I do to embed my custom processor into my component? Can I simply add the php file or should I do some configuration?