MIGXdb: joined tables: how to add / show from corresponding table

Hi there,
I am completely lost with a simple MIGXdb configuration.

Schema:

    <?xml version="1.0" encoding="UTF-8"?>
<model package="frankcmp" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
   	<object class="Frankprodukttyp" table="frankprodukttyp" extends="xPDOSimpleObject">
		<field key="name" dbtype="varchar" precision="255" phptype="string" null="true" />
		<aggregate alias="Frankfiles" class="Frankfiles" local="id" foreign="prodtyp" cardinality="one" owner="foreign" />
	</object>
	<object class="Frankfiles" table="frankfiles" extends="xPDOSimpleObject">
		<field key="name" dbtype="varchar" precision="255" phptype="string" null="true" />
		<field key="file" dbtype="varchar" precision="255" phptype="string" null="true" />
		<field key="doctype" dbtype="varchar" precision="255" phptype="string" null="true" />
		<field key="prodtyp" dbtype="int" precision="11" phptype="integer" null="true" />
		<composite alias="Frankprodukttyp" class="Frankprodukttyp" local="prodtyp" foreign="id" cardinality="many" owner="local" />
	</object>
</model>

Two MIGX Configurations:
“Product Types”

{
  "formtabs":[
    {
      "MIGX_id":6,
      "caption":"Produkttypen",
      "print_before_tabs":"0",
      "fields":[
        {
          "MIGX_id":24,
          "field":"name",
          "caption":"Typname",
          "description":"z.B. Innent\u00fcr, Rahment\u00fcr",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"text",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":1
        },
        {
          "MIGX_id":31,
          "field":"files",
          "caption":"Files",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"migxdb",
          "validation":"",
          "configs":"FrankFiles",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":2
        }
      ],
      "pos":1
    }
  ],
  "contextmenus":"update||duplicate||remove",
  "actionbuttons":"addItem",
  "columnbuttons":"",
  "filters":"",
  "extended":{
    "migx_add":"",
    "disable_add_item":"",
    "add_items_directly":"",
    "formcaption":"Frank Typen",
    "update_win_title":"Franktypen",
    "win_id":"franktypen",
    "maxRecords":"",
    "addNewItemAt":"bottom",
    "media_source_id":4,
    "multiple_formtabs":"",
    "multiple_formtabs_label":"",
    "multiple_formtabs_field":"",
    "multiple_formtabs_optionstext":"",
    "multiple_formtabs_optionsvalue":"",
    "actionbuttonsperrow":4,
    "winbuttonslist":"",
    "extrahandlers":"",
    "filtersperrow":4,
    "packageName":"frank",
    "classname":"Frankprodukttyp",
    "task":"",
    "getlistsort":"",
    "getlistsortdir":"",
    "sortconfig":"",
    "gridpagesize":"",
    "use_custom_prefix":"0",
    "prefix":"",
    "grid":"",
    "gridload_mode":1,
    "check_resid":1,
    "check_resid_TV":"",
    "join_alias":"",
    "has_jointable":"yes",
    "getlistwhere":"",
    "joins":[
      {
        "alias":"Frankfiles",
        "selectfiles":"id,name"
      }
    ],
    "hooksnippets":"",
    "cmpmaincaption":"",
    "cmptabcaption":"",
    "cmptabdescription":"",
    "cmptabcontroller":"",
    "winbuttons":"",
    "onsubmitsuccess":"",
    "submitparams":""
  },
  "columns":[
    {
      "MIGX_id":2,
      "header":"id",
      "dataIndex":"id",
      "width":10,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":3,
      "dataIndex":"name",
      "header":"name"
    },
    {
      "MIGX_id":4,
      "header":"Files",
      "dataIndex":"files",
      "width":250,
      "sortable":"false",
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"FrankFiles",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    }
  ],
  "category":""
} 

“Product Files”

{
  "formtabs":[
    {
      "MIGX_id":7,
      "caption":"Frank Files",
      "print_before_tabs":"0",
      "fields":[
        {
          "MIGX_id":25,
          "field":"id",
          "caption":"id",
          "pos":1
        },
        {
          "MIGX_id":26,
          "field":"name",
          "caption":"name",
          "pos":2
        },
        {
          "MIGX_id":27,
          "field":"file",
          "caption":"file",
          "pos":3
        },
        {
          "MIGX_id":28,
          "field":"doctype",
          "caption":"doctype",
          "pos":4
        },
        {
          "MIGX_id":29,
          "field":"prodtyp",
          "caption":"prodtyp",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"number",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"none",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"[[+Franktypen.id]]",
          "useDefaultIfEmpty":"0",
          "pos":5
        },
        {
          "MIGX_id":30,
          "field":"Frankprodukttyp_name",
          "caption":"Frankprodukttyp_name",
          "pos":6
        }
      ],
      "pos":1
    }
  ],
  "contextmenus":"update||duplicate||addafter||remove",
  "actionbuttons":"addItem",
  "columnbuttons":"",
  "filters":"",
  "extended":{
    "migx_add":"",
    "disable_add_item":"",
    "add_items_directly":"",
    "formcaption":"Frank Files",
    "update_win_title":"FrankFiles",
    "win_id":"frankfiles",
    "maxRecords":"",
    "addNewItemAt":"bottom",
    "media_source_id":4,
    "multiple_formtabs":"",
    "multiple_formtabs_label":"",
    "multiple_formtabs_field":"",
    "multiple_formtabs_optionstext":"",
    "multiple_formtabs_optionsvalue":"",
    "actionbuttonsperrow":4,
    "winbuttonslist":"",
    "extrahandlers":"",
    "filtersperrow":4,
    "packageName":"frank",
    "classname":"Frankfiles",
    "task":"",
    "getlistsort":"",
    "getlistsortdir":"",
    "sortconfig":"",
    "gridpagesize":"",
    "use_custom_prefix":"0",
    "prefix":"",
    "grid":"",
    "gridload_mode":2,
    "check_resid":"0",
    "check_resid_TV":"",
    "join_alias":"",
    "has_jointable":"no",
    "getlistwhere":"",
    "joins":[
      {
        "alias":"Frankprodukttyp"
      },
      {
        "selectfields":"name,id"
      }
    ],
    "hooksnippets":"",
    "cmpmaincaption":"",
    "cmptabcaption":"",
    "cmptabdescription":"",
    "cmptabcontroller":"",
    "winbuttons":"",
    "onsubmitsuccess":"",
    "submitparams":""
  },
  "columns":[
    {
      "MIGX_id":2,
      "dataIndex":"id",
      "header":"id"
    },
    {
      "MIGX_id":3,
      "dataIndex":"name",
      "header":"name"
    },
    {
      "MIGX_id":4,
      "dataIndex":"file",
      "header":"file"
    },
    {
      "MIGX_id":5,
      "dataIndex":"doctype",
      "header":"doctype"
    },
    {
      "MIGX_id":6,
      "dataIndex":"Frankprodukttyp_name",
      "header":"Frankprodukttyp_name"
    }
  ],
  "category":""
}

I want for “Types”

And for “Files” a list of all files with the type it belongs to:

Problems:

  • how to insert the field “prodtyp” automatically with the “id” of the type.
  • how to list the files belonging to a type?

Glad for any hint. Thank you.

Hi Fabian,
could you solve your questions allready?

Hi Bruno,
the problem with inserting the id automatically is solved. I think it was just a fundemental missunderstanding of how aggregate / composite and local / foreign key concept works.

Interestingly when I join the two tables with in the field Join Alias I can not select fields from the joined table. This works, when I use the field Joins. But then the inserting of the id does not work.
image

And secondly I don’t get it how to list all corresponding files of the joined table, as shown in the first picture above.

did you change your xml schema now? If so, could you post it again, please

    <?xml version="1.0" encoding="UTF-8"?>
<model package="frank" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
   	<object class="Frankprodukttyp" table="frankprodukttyp" extends="xPDOSimpleObject">
		<field key="name" dbtype="varchar" precision="255" phptype="string" null="true" />
		<composite alias="Frankfiles" class="Frankfiles" local="id" foreign="prodtyp" cardinality="many" owner="local" />
	</object>
    
	<object class="Frankfiles" table="frankfiles" extends="xPDOSimpleObject">
		<field key="name" dbtype="varchar" precision="255" phptype="string" null="true" />
		<field key="file" dbtype="varchar" precision="255" phptype="string" null="true" />
		<field key="doctype" dbtype="varchar" precision="255" phptype="string" null="true" />
		<field key="prodtyp" dbtype="int" precision="11" phptype="integer" null="false" />
		<aggregate alias="Frankprodukttyp" class="Frankprodukttyp" local="prodtyp" foreign="id" cardinality="one" owner="foreign" />
	</object>
</model>

Categories MIGX config:

{
  "formtabs":[
    {
      "MIGX_id":6,
      "caption":"Produkttypen",
      "print_before_tabs":"0",
      "fields":[
        {
          "MIGX_id":24,
          "field":"name",
          "caption":"Typname",
          "description":"z.B. Innent\u00fcr, Rahment\u00fcr",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"text",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":1
        },
        {
          "MIGX_id":31,
          "field":"files",
          "caption":"Files",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"migxdb",
          "validation":"",
          "configs":"frankfiles",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":2
        }
      ],
      "pos":1
    }
  ],
  "contextmenus":"update||duplicate||remove",
  "actionbuttons":"addItem",
  "columnbuttons":"",
  "filters":"",
  "extended":{
    "migx_add":"",
    "disable_add_item":"",
    "add_items_directly":"",
    "formcaption":"Frank Typen",
    "update_win_title":"Franktypen",
    "win_id":"franktypen",
    "maxRecords":"",
    "addNewItemAt":"bottom",
    "media_source_id":4,
    "multiple_formtabs":"",
    "multiple_formtabs_label":"",
    "multiple_formtabs_field":"",
    "multiple_formtabs_optionstext":"",
    "multiple_formtabs_optionsvalue":"",
    "actionbuttonsperrow":4,
    "winbuttonslist":"",
    "extrahandlers":"",
    "filtersperrow":4,
    "packageName":"frank",
    "classname":"Frankprodukttyp",
    "task":"",
    "getlistsort":"",
    "getlistsortdir":"",
    "sortconfig":"",
    "gridpagesize":"",
    "use_custom_prefix":"0",
    "prefix":"",
    "grid":"",
    "gridload_mode":2,
    "check_resid":1,
    "check_resid_TV":"",
    "join_alias":"",
    "has_jointable":"no",
    "getlistwhere":"",
    "joins":[
      {
        "alias":"Frankfiles"
      },
      {
        "selectfields":"name"
      }
    ],
    "hooksnippets":"",
    "cmpmaincaption":"Frank Files",
    "cmptabcaption":"Frank Typen",
    "cmptabdescription":"Types",
    "cmptabcontroller":"",
    "winbuttons":"",
    "onsubmitsuccess":"",
    "submitparams":""
  },
  "columns":[
    {
      "MIGX_id":2,
      "header":"id",
      "dataIndex":"id",
      "width":10,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":3,
      "dataIndex":"name",
      "header":"name"
    },
    {
      "MIGX_id":6,
      "dataIndex":"Frankfiles_name",
      "header":"Frankfiles_name"
    }
  ],
  "category":""
}

Files MIGX config:

{
  "formtabs":[
    {
      "MIGX_id":7,
      "caption":"Frank Files",
      "print_before_tabs":"0",
      "fields":[
        {
          "MIGX_id":26,
          "field":"name",
          "caption":"Filename",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"text",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":1
        },
        {
          "MIGX_id":27,
          "field":"file",
          "caption":"File",
          "description":"Link zum File",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"file",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":[
            {
              "MIGX_id":1,
              "context":"web",
              "sourceid":4
            },
            {
              "MIGX_id":2,
              "context":"fr",
              "sourceid":4
            }
          ],
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":2
        },
        {
          "MIGX_id":28,
          "field":"doctype",
          "caption":"Dokumenttyp",
          "description":"PDF, DXF?",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"option",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"PDF||DXF||",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":3
        }
      ],
      "pos":1
    }
  ],
  "contextmenus":"update||duplicate||addafter||remove",
  "actionbuttons":"addItem",
  "columnbuttons":"",
  "filters":"",
  "extended":{
    "migx_add":"",
    "disable_add_item":"",
    "add_items_directly":"",
    "formcaption":"Frank Files",
    "update_win_title":"FrankFiles",
    "win_id":"frankfiles",
    "maxRecords":"",
    "addNewItemAt":"bottom",
    "media_source_id":4,
    "multiple_formtabs":"",
    "multiple_formtabs_label":"",
    "multiple_formtabs_field":"",
    "multiple_formtabs_optionstext":"",
    "multiple_formtabs_optionsvalue":"",
    "actionbuttonsperrow":4,
    "winbuttonslist":"",
    "extrahandlers":"",
    "filtersperrow":4,
    "packageName":"frank",
    "classname":"Frankfiles",
    "task":"",
    "getlistsort":"",
    "getlistsortdir":"",
    "sortconfig":"",
    "gridpagesize":"",
    "use_custom_prefix":"0",
    "prefix":"",
    "grid":"",
    "gridload_mode":2,
    "check_resid":1,
    "check_resid_TV":"",
    "join_alias":"Frankprodukttyp",
    "has_jointable":"no",
    "getlistwhere":"",
    "joins":"",
    "hooksnippets":"",
    "cmpmaincaption":"Frank Files",
    "cmptabcaption":"Frank Files",
    "cmptabdescription":"Files",
    "cmptabcontroller":"",
    "winbuttons":"",
    "onsubmitsuccess":"",
    "submitparams":""
  },
  "columns":[
    {
      "MIGX_id":2,
      "header":"id",
      "dataIndex":"id",
      "width":10,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":3,
      "header":"Filename",
      "dataIndex":"name",
      "width":150,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":"this.textEditor"
    },
    {
      "MIGX_id":4,
      "header":"File",
      "dataIndex":"file",
      "width":150,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":5,
      "header":"Dokmententyp",
      "dataIndex":"doctype",
      "width":50,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":8,
      "header":"prodtyp",
      "dataIndex":"prodtyp",
      "width":100,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    }
  ],
  "category":""
}

You can’t select the fields of the table which you have joined with joinalias, but you can add this fields manually by using the prefix ‘Joined’
for example: Joined_name
you could also use both, the joinalias and the joins - field.

In the productyte - config, you don’t need and don’t want the join to the files - table.
To get the selected files within a column, you can use the renderChunk - renderer and put something like that into the renderChunk template

<ul>
[[migxLoopCollection?
&packageName=`frank`
&classname=`Frankfiles`
&where=`{"prodtyp":"[[+id]]"}`
&tpl=`@CODE:<li>{{+name}}</li>`
]]
</ul>

Thank you Bruno! Works like a charm!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.