We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47602
    • 5 Posts
    I'm a novice at using MODx Revolution (2.2.8-pl). It's a great CMS and I really like most of its features but I can't seem to find what I'm looking for when it comes to linking database objects from the same package. I found this wonderful tool called MIGx, which is great and all, but I can't really figure out how to use its form tabs option to write fields in different objects.

    To make things short, I've been working on a photo/portfolio website and I need to create a couple of items in the database to store all the projects the photographer has worked on. Basically what I'm trying to do is to add items into the portfolio table, each having a description, date, quote, and a list of images. Here is where it gets nasty.

    Each image needs to have, aside from the obvious image, its own description, quote, quote color, tag ... etc.

    So my guess is that I need two objects in the same package and a link between them of some sort. In the first object, the user enters the main details of the project, like where it was shot, the crew, a short description, date, a main image and a thumbnail ... but when he reaches the "item_sections" field in the first object, I want to give him the possibility to add as many other sections as he wants. Each section having its own image, image description, text color, tags ... etc.



    My current XML schema looks something like this:
    (It's my first try and I really hope I got everything in order)


    <?xml version="1.0" encoding="UTF-8"?>
    
    <model package="portfolio" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="portfolio" phpdoc-subpackage="model" version="1.1">
    
    	<object class="portfolio_table" table="portfolio" extends="xPDOSimpleObject">
    		<field key="item_type" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
    		<field key="item_date" dbtype="varchar" precision="10" phptype="string" null="false" default=""/>
    		<field key="item_author" dbtype="varchar" precision="30" phptype="string" null="false" default=""/>
    		<field key="item_title" dbtype="varchar" precision="250" phptype="string" null="false" default="" />
    		<field key="item_description" dbtype="varchar" precision="500" phptype="string" null="false" default="" />
    		<field key="item_text_color" dbtype="varchar" precision="10" phptype="string" null="false" default="grey" />
    		<field key="item_sections" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
    		<field key="item_keywords" dbtype="varchar" precision="250" phptype="string" null="false" default="" />
    		<field key="main_img" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
    		<field key="thumb_img" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
    		<field key="published" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    	        <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                           <column key="id" collation="A" null="false" />
                    </index>
    		<aggregate alias="sections" class="item_sections" local="id" foreign="content_id" cardinality="one" owner="foreign" />		
    	</object>
    	<object class="item_sections" table="item_content" extends="xPDOSimpleObject">
    		<field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native"/>
    		<field key="content_id" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
    		<field key="content_type" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
    		<field key="content_title" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
    		<field key="content_quote" dbtype="varchar" precision="500" phptype="string" null="false" default=""/>
    		<field key="content_color" dbtype="varchar" precision="20" phptype="string" null="false" default="grey"/>
    		<field key="content_main" dbtype="varchar" precision="2000" phptype="string" null="false" default="" />
            <field key="content_image" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
    		<field key="content_tags" dbtype="varchar" precision="10" phptype="string" null="false" default=""/>
    		
    		<composite alias="contentOwner" class="portfolio_table" local="content_id" foreign="id" cardinality="many" owner="local" />
    	</object>
    
    </model>




    I've created the package in MIGx, parsed the xml schema, created the tables and have added columns and formtabs in the MIGx config window, but now I don't know how to tie everything together.

    So the user starts adding data to the first object "portfolio_table", and once he reaches "item_sections", he can add as many "content" fields as he wants.

    item.id - auto increment
    item.type
    item.date
    item.author
    item.title
    item/description
    item.text.color
    item sections - "Main Content"
    id - auto increment
    content.id - link to item.id
    content.type
    content.title
    content.quote
    content.color
    content.main
    content.image
    content.tags

    item.keywords - "Keywords"
    main.img
    thumb.img



    I found this related question and have modified the template variable, but it still isn't writing anything in the second table.
    http://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials/migxdb.create-a-basic-gallery-management-from-scratch-with-migxdb

    Any help would be much appreciated.

    Kind regards,

    Alex

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

      • 4172
      • 5,888 Posts
      seems this is related, and may be, it can help:
      https://forums.modx.com/thread/89898/nested-migxdb-element-adding-mostly-empty-records-to-parent-migxdb-element#dis-post-494176

      there are some more discussions about nested MIGXdb - grids inside another MIGXdb - CMP at the forums.

      you don't need the 'id' - field in your schema
      This is added automatically by xpdo, when you extend xPDOSimpleObject

          <object class="item_sections" table="item_content" extends="xPDOSimpleObject">
              <field key="content_id" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
              <field key="content_type" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
              <field key="content_title" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
              <field key="content_quote" dbtype="varchar" precision="500" phptype="string" null="false" default=""/>
              <field key="content_color" dbtype="varchar" precision="20" phptype="string" null="false" default="grey"/>
              <field key="content_main" dbtype="varchar" precision="2000" phptype="string" null="false" default="" />
              <field key="content_image" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
              <field key="content_tags" dbtype="varchar" precision="10" phptype="string" null="false" default=""/>
               
              <composite alias="contentOwner" class="portfolio_table" local="content_id" foreign="id" cardinality="many" owner="local" />
          </object>


      If you have still issues, getting it working, let me know.

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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 47602
        • 5 Posts
        Thank you for your answer. I think it put me on the right track smiley

        I still haven't made it work though.
        Here is my new schema:

        <?xml version="1.0" encoding="UTF-8"?>
        <model package="portfolio" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="portfolio" phpdoc-subpackage="model" version="1.1">
        	<object class="portfolio_table" table="portfolio" extends="xPDOSimpleObject">
        		<field key="item_type" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
        		<field key="item_date" dbtype="varchar" precision="10" phptype="string" null="false" default=""/>
        		<field key="item_author" dbtype="varchar" precision="30" phptype="string" null="false" default=""/>
        		<field key="item_title" dbtype="varchar" precision="250" phptype="string" null="false" default="" />
        		<field key="item_description" dbtype="varchar" precision="500" phptype="string" null="false" default="" />
        		<field key="item_text_color" dbtype="varchar" precision="10" phptype="string" null="false" default="grey" />
        		<field key="item_keywords" dbtype="varchar" precision="250" phptype="string" null="false" default="" />
        		<field key="item_content" dbtype="varchar" precision="1000" phptype="string" null="false" default="" />
        		<field key="main_img" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
        		<field key="thumb_img" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
        		<field key="published" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
        		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                        <column key="id" collation="A" null="false" />
                </index>
        		<aggregate alias="sections" class="item_sections" local="id" foreign="content_id" cardinality="one" owner="foreign" />		
        	</object>
        	<object class="item_sections" table="item_content" extends="xPDOSimpleObject">
        		<field key="content_id" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
        		<field key="content_type" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
        		<field key="content_title" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
        		<field key="content_quote" dbtype="varchar" precision="500" phptype="string" null="false" default=""/>
        		<field key="content_color" dbtype="varchar" precision="20" phptype="string" null="false" default="grey"/>
        		<field key="content_main" dbtype="varchar" precision="2000" phptype="string" null="false" default="" />
                <field key="content_image" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
        		<field key="content_tags" dbtype="varchar" precision="10" phptype="string" null="false" default=""/>
        		
        		<composite alias="contentOwner" class="portfolio_table" local="content_id" foreign="id" cardinality="many" owner="local" />
        	</object>
        </model>



        I still have some doubts regarding how the composite/aggregate tags work, but hopefully they will in this case smiley

        The JSON from the first object in the package "portfolio_table":

        {
          "formtabs":[
            {
              "MIGX_id":1,
              "caption":"Add new item to the portfolio",
              "print_before_tabs":"0",
              "fields":[
                {
                  "MIGX_id":1,
                  "field":"item_type",
                  "caption":"Item type",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"required",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":2,
                  "field":"item_date",
                  "caption":"Date",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"date",
                  "validation":"required",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":3,
                  "field":"item_author",
                  "caption":"Author",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":4,
                  "field":"item_title",
                  "caption":"Title",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":5,
                  "field":"item_description",
                  "caption":"Short description",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"required",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":11,
                  "field":"item_text_color",
                  "caption":"Text color",
                  "description":"The text color for the short description text (can be white, grey or black)",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":6,
                  "field":"item_content",
                  "caption":"Main Content",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"AddNewSection",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":7,
                  "field":"item_keywords",
                  "caption":"Keywords",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":8,
                  "field":"main_img",
                  "caption":"Large image",
                  "description":"The large image posted inside the article",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"image",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":9,
                  "field":"thumb_img",
                  "caption":"Thumbnail",
                  "description":"The thumbnail image",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"image",
                  "validation":"required",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":10,
                  "field":"published",
                  "caption":"Publishing status",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"checkbox",
                  "validation":"required",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"yes==1",
                  "default":"0"
                }
              ]
            }
          ],
          "contextmenus":"update||duplicate||publish||unpublish||remove",
          "actionbuttons":"addItem",
          "columnbuttons":"",
          "filters":"[]",
          "extended":{
            "migx_add":"Add new item",
            "formcaption":"",
            "update_win_title":"",
            "win_id":"Portfolio_main",
            "maxRecords":"",
            "addNewItemAt":"bottom",
            "multiple_formtabs":"",
            "actionbuttonsperrow":4,
            "winbuttonslist":"",
            "extrahandlers":"",
            "filtersperrow":4,
            "packageName":"portfolio",
            "classname":"portfolio_table",
            "task":"",
            "getlistsort":"",
            "getlistsortdir":"",
            "use_custom_prefix":"0",
            "prefix":"",
            "grid":"",
            "gridload_mode":1,
            "check_resid":1,
            "check_resid_TV":"",
            "join_alias":"",
            "has_jointable":"no",
            "getlistwhere":"",
            "joins":"",
            "cmpmaincaption":"Portfolio",
            "cmptabcaption":"Manage Portfolio",
            "cmptabdescription":"Add, edit and remove items from the portfolio",
            "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":3,
              "header":"Type",
              "dataIndex":"item_type",
              "width":"",
              "sortable":true,
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":2,
              "header":"Date",
              "dataIndex":"item_date",
              "width":"",
              "sortable":true,
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":4,
              "header":"Author",
              "dataIndex":"item_author",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":5,
              "header":"Title",
              "dataIndex":"item_title",
              "width":"",
              "sortable":true,
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":6,
              "header":"Short description",
              "dataIndex":"item_description",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":12,
              "header":"Text color",
              "dataIndex":"item_text_color",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":8,
              "header":"Keywords",
              "dataIndex":"item_keywords",
              "width":"",
              "sortable":true,
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":9,
              "header":"Main image",
              "dataIndex":"main_img",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":10,
              "header":"Thumbnail",
              "dataIndex":"thumb_img",
              "width":"",
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":11,
              "header":"Status",
              "dataIndex":"published",
              "width":"",
              "sortable":true,
              "show_in_grid":1,
              "renderer":"this.renderCrossTick",
              "clickaction":"switchOption",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":[
                {
                  "MIGX_id":1,
                  "name":"",
                  "value":"",
                  "clickaction":"",
                  "handler":"",
                  "image":""
                }
              ]
            }
          ]
        }



        And the JSON from the second object "item_content":

        {
          "formtabs":[
            {
              "MIGX_id":1,
              "caption":"Manage Item Content",
              "print_before_tabs":"0",
              "fields":[
                {
                  "MIGX_id":1,
                  "field":"content_type",
                  "caption":"Type",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"required",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":2,
                  "field":"content_title",
                  "caption":"Title",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"required",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":3,
                  "field":"content_quote",
                  "caption":"Quote",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":4,
                  "field":"content_color",
                  "caption":"Quote color",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":5,
                  "field":"content_main",
                  "caption":"Main description",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"richtext",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":6,
                  "field":"content_image",
                  "caption":"Image",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"image",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                },
                {
                  "MIGX_id":7,
                  "field":"content_tags",
                  "caption":"Tags",
                  "description":"",
                  "description_is_code":"0",
                  "inputTV":"",
                  "inputTVtype":"",
                  "validation":"",
                  "configs":"",
                  "restrictive_condition":"",
                  "display":"",
                  "sourceFrom":"config",
                  "sources":"[]",
                  "inputOptionValues":"",
                  "default":""
                }
              ]
            }
          ],
          "contextmenus":"",
          "actionbuttons":"addItem",
          "columnbuttons":"update||duplicate||publish||unpublish||remove",
          "filters":"[]",
          "extended":{
            "migx_add":"Add section",
            "formcaption":"",
            "update_win_title":"",
            "win_id":"item_sections",
            "maxRecords":"",
            "addNewItemAt":"bottom",
            "multiple_formtabs":"",
            "actionbuttonsperrow":4,
            "winbuttonslist":"",
            "extrahandlers":"",
            "filtersperrow":4,
            "packageName":"portfolio",
            "classname":"item_content",
            "task":"",
            "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":"AddSections",
            "cmptabcaption":"Manage item sections",
            "cmptabdescription":"Add, edit or remove sections inside the portfolio items",
            "cmptabcontroller":"",
            "winbuttons":"",
            "onsubmitsuccess":"",
            "submitparams":""
          },
          "columns":[
            {
              "MIGX_id":1,
              "header":"id",
              "dataIndex":"id",
              "width":100,
              "sortable":true,
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":2,
              "header":"Content ID",
              "dataIndex":"content_id",
              "width":100,
              "sortable":true,
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":3,
              "header":"Type",
              "dataIndex":"content_type",
              "width":150,
              "sortable":true,
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":4,
              "header":"Title",
              "dataIndex":"content_title",
              "width":200,
              "sortable":true,
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":5,
              "header":"Quote",
              "dataIndex":"content_quote",
              "width":200,
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":6,
              "header":"Quote color",
              "dataIndex":"content_color",
              "width":100,
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":7,
              "header":"Main description",
              "dataIndex":"content_main",
              "width":300,
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":8,
              "header":"Image",
              "dataIndex":"content_image",
              "width":150,
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            },
            {
              "MIGX_id":9,
              "header":"Tags",
              "dataIndex":"content_tags",
              "width":100,
              "sortable":"false",
              "show_in_grid":1,
              "renderer":"",
              "clickaction":"",
              "selectorconfig":"",
              "renderchunktpl":"",
              "renderoptions":"[]"
            }
          ]
        }



        • discuss.answer
          • 4172
          • 5,888 Posts
          Did some mods and tested it.

          varchar max-size is 255, so I used text - dbtype

          and I changed the aggregate and composite
          and added another (in the table not existing field) for the sections-grid
          and added a join-alias for the sections-grid.

          This did work:

          <?xml version="1.0" encoding="UTF-8"?>
          <model package="portfolio" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="portfolio" phpdoc-subpackage="model" version="1.1">
              <object class="portfolio_table" table="portfolio" extends="xPDOSimpleObject">
                  <field key="item_type" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
                  <field key="item_date" dbtype="varchar" precision="10" phptype="string" null="false" default=""/>
                  <field key="item_author" dbtype="varchar" precision="30" phptype="string" null="false" default=""/>
                  <field key="item_title" dbtype="varchar" precision="250" phptype="string" null="false" default="" />
                  <field key="item_description" dbtype="text" phptype="string" null="false" default="" />
                  <field key="item_text_color" dbtype="varchar" precision="10" phptype="string" null="false" default="grey" />
                  <field key="item_keywords" dbtype="varchar" precision="250" phptype="string" null="false" default="" />
                  <field key="item_content" dbtype="text" phptype="string" null="false" default="" />
                  <field key="main_img" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
                  <field key="thumb_img" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
                  <field key="published" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
                  <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                          <column key="id" collation="A" null="false" />
                  </index>
                  <composite alias="sections" class="item_sections" local="id" foreign="content_id" cardinality="many" owner="local" />       
              </object>
              <object class="item_sections" table="item_content" extends="xPDOSimpleObject">
                  <field key="content_id" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
                  <field key="content_type" dbtype="varchar" precision="20" phptype="string" null="false" default=""/>
                  <field key="content_title" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
                  <field key="content_quote" dbtype="text" phptype="string" null="false" default=""/>
                  <field key="content_color" dbtype="varchar" precision="20" phptype="string" null="false" default="grey"/>
                  <field key="content_main" dbtype="text" phptype="string" null="false" default="" />
                  <field key="content_image" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
                  <field key="content_tags" dbtype="varchar" precision="10" phptype="string" null="false" default=""/>
                   
                  <aggregate alias="contentOwner" class="portfolio_table" local="content_id" foreign="id" cardinality="one" owner="foreign" />
              </object>
          </model>
          


          config with name 'portfolio'
          {
            "formtabs":[
              {
                "MIGX_id":34,
                "caption":"portfolio",
                "print_before_tabs":"0",
                "fields":[
                  {
                    "MIGX_id":206,
                    "field":"item_type",
                    "caption":"Item type",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"",
                    "validation":"required",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":1
                  },
                  {
                    "MIGX_id":207,
                    "field":"item_date",
                    "caption":"Date",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"date",
                    "validation":"required",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":2
                  },
                  {
                    "MIGX_id":208,
                    "field":"item_author",
                    "caption":"Author",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":3
                  },
                  {
                    "MIGX_id":209,
                    "field":"item_title",
                    "caption":"Title",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":4
                  },
                  {
                    "MIGX_id":210,
                    "field":"item_description",
                    "caption":"Short description",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"",
                    "validation":"required",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":5
                  },
                  {
                    "MIGX_id":211,
                    "field":"item_text_color",
                    "caption":"Text color",
                    "description":"The text color for the short description text (can be white, grey or black)",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":6
                  },
                  {
                    "MIGX_id":212,
                    "field":"item_content",
                    "caption":"Main Content",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"textarea",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":7
                  },
                  {
                    "MIGX_id":213,
                    "field":"item_keywords",
                    "caption":"Keywords",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":8
                  },
                  {
                    "MIGX_id":214,
                    "field":"main_img",
                    "caption":"Large image",
                    "description":"The large image posted inside the article",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"image",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":9
                  },
                  {
                    "MIGX_id":215,
                    "field":"thumb_img",
                    "caption":"Thumbnail",
                    "description":"The thumbnail image",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"image",
                    "validation":"required",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"[]",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":10
                  },
                  {
                    "MIGX_id":216,
                    "field":"published",
                    "caption":"Publishing status",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"checkbox",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"",
                    "inputOptionValues":"yes==1",
                    "default":"0",
                    "pos":11
                  }
                ],
                "pos":1
              },
              {
                "MIGX_id":35,
                "caption":"sections",
                "print_before_tabs":"0",
                "fields":[
                  {
                    "MIGX_id":217,
                    "field":"portfolio_sections",
                    "caption":"Sections",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"migxdb",
                    "validation":"",
                    "configs":"portfolio_sections",
                    "restrictive_condition":"",
                    "display":"",
                    "sourceFrom":"config",
                    "sources":"",
                    "inputOptionValues":"",
                    "default":"",
                    "pos":1
                  }
                ],
                "pos":2
              }
            ],
            "contextmenus":"update||duplicate||publish||unpublish||remove",
            "actionbuttons":"addItem",
            "columnbuttons":"",
            "filters":"",
            "extended":{
              "migx_add":"Add new item",
              "disable_add_item":"",
              "formcaption":"",
              "update_win_title":"",
              "win_id":"Portfolio_main",
              "maxRecords":"",
              "addNewItemAt":"bottom",
              "multiple_formtabs":"",
              "actionbuttonsperrow":4,
              "winbuttonslist":"",
              "extrahandlers":"",
              "filtersperrow":4,
              "packageName":"portfolio",
              "classname":"portfolio_table",
              "task":"",
              "getlistsort":"",
              "getlistsortdir":"",
              "use_custom_prefix":"0",
              "prefix":"",
              "grid":"",
              "gridload_mode":1,
              "check_resid":1,
              "check_resid_TV":"",
              "join_alias":"",
              "has_jointable":"no",
              "getlistwhere":"",
              "joins":"",
              "cmpmaincaption":"Portfolio",
              "cmptabcaption":"Manage Portfolio",
              "cmptabdescription":"Add, edit and remove items from the portfolio",
              "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":3,
                "header":"Type",
                "dataIndex":"item_type",
                "width":"",
                "sortable":true,
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":2,
                "header":"Date",
                "dataIndex":"item_date",
                "width":"",
                "sortable":true,
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":4,
                "header":"Author",
                "dataIndex":"item_author",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":5,
                "header":"Title",
                "dataIndex":"item_title",
                "width":"",
                "sortable":true,
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":6,
                "header":"Short description",
                "dataIndex":"item_description",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":12,
                "header":"Text color",
                "dataIndex":"item_text_color",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":8,
                "header":"Keywords",
                "dataIndex":"item_keywords",
                "width":"",
                "sortable":true,
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":9,
                "header":"Main image",
                "dataIndex":"main_img",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":10,
                "header":"Thumbnail",
                "dataIndex":"thumb_img",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":"[]"
              },
              {
                "MIGX_id":11,
                "header":"Status",
                "dataIndex":"published",
                "width":"",
                "sortable":true,
                "show_in_grid":1,
                "renderer":"this.renderCrossTick",
                "clickaction":"switchOption",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":[
                  {
                    "MIGX_id":1,
                    "name":"",
                    "value":"",
                    "clickaction":"",
                    "handler":"",
                    "image":""
                  }
                ]
              }
            ]
          }


          config with name 'portfolio_sections'
          {
            "formtabs":[
              {
                "MIGX_id":36,
                "caption":"Section",
                "print_before_tabs":"0",
                "fields":[
                  {
                    "MIGX_id":218,
                    "field":"content_title",
                    "caption":"Title",
                    "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":"",
              "disable_add_item":"",
              "formcaption":"",
              "update_win_title":"",
              "win_id":"",
              "maxRecords":"",
              "addNewItemAt":"bottom",
              "multiple_formtabs":"",
              "actionbuttonsperrow":4,
              "winbuttonslist":"",
              "extrahandlers":"",
              "filtersperrow":4,
              "packageName":"portfolio",
              "classname":"item_sections",
              "task":"",
              "getlistsort":"",
              "getlistsortdir":"",
              "use_custom_prefix":"0",
              "prefix":"",
              "grid":"",
              "gridload_mode":2,
              "check_resid":1,
              "check_resid_TV":"",
              "join_alias":"contentOwner",
              "has_jointable":"no",
              "getlistwhere":"",
              "joins":"",
              "cmpmaincaption":"",
              "cmptabcaption":"",
              "cmptabdescription":"",
              "cmptabcontroller":"",
              "winbuttons":"",
              "onsubmitsuccess":"",
              "submitparams":""
            },
            "columns":[
              {
                "MIGX_id":1,
                "header":"ID",
                "dataIndex":"id",
                "width":10,
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":""
              },
              {
                "MIGX_id":2,
                "header":"Title",
                "dataIndex":"content_title",
                "width":"",
                "sortable":"false",
                "show_in_grid":1,
                "renderer":"",
                "clickaction":"",
                "selectorconfig":"",
                "renderchunktpl":"",
                "renderoptions":""
              }
            ]
          }
          
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 47602
            • 5 Posts
            Thank you very much. It worked like a charm.
            Your solution is much more elegant than what I had in mind. I will study it. smiley

            Now. the upcoming task is how to query all the new info using BloX. But that's a whole nother question.

            Thank you again.
              • 4172
              • 5,888 Posts
              you can also use migxLoopCollection, nested into another migxLoopCollection-tpl
              or pdoResources should also work great to get the items listed.

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

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 47602
                • 5 Posts
                If it's not too much trouble, could you please give me an example, based on the info above?
                I haven't worked with the snippets you've mentioned above, not to mention trying to join two tables and output the data.

                Up until now, I've been creating my own snippets, like:

                <?php
                if (!$from)
                  return false;
                else {
                  $fields = ($fields != "") ? "$fields" : "*";
                  $where = ($where != "") ? "WHERE $where" : "";
                  $orderby = ($orderby != "") ? "ORDER BY $orderby" : "";
                  $limit = ($limit != "") ? "LIMIT $limit" : "";
                }
                
                $output = '';
                
                $results = $modx->query("SELECT $fields FROM $from $where $orderby $limit");
                
                while ($row = $results->fetch(PDO::FETCH_ASSOC)) {
                
                  $properties['item']['id'] = $row['id'];
                  $properties['item']['type'] = $row['item_type'];
                  $properties['item']['date'] = $row['item_date'];
                  $properties['item']['author'] = $row['item_author'];
                  $properties['item']['title'] = $row['item_title'];
                  $properties['short']['content'] = $row['item_description'];
                  $properties['short']['text_color'] = $row['item_text_color'];
                  $properties['main']['content'] = $row['item_content'];
                  $properties['large']['image'] = $row['main_img'];
                  $properties['thumb']['image'] = $row['thumb_img'];
                  $properties['item']['keywords'] = $row['item_keywords'];
                  
                  $output .= $modx->getChunk("$tpl",$properties);
                
                }
                
                return $output;


                But the trouble with this way is that I constantly have to update the rows and the properties.

                Thank you for your time and patience.