placeholders in where clause not working correctly.
I am using migx to generate a CMP for my custom table. (MIGX 1) This table has both one to many and many to many relations to other custom tables.
In my form tabs, I am using a nested migx config (MIGX 2) to manage the 'children' records of the 'parent'.
I save the relations in an 'after' snippet in MIGX 2 config. When I was using a listbox, I could use a 'before' snippet to populate the field's value with a string of related ID's, however this does not seem to affect a nested MIGX TV.
So I tried using a where clause in MIGX 2 db-settings, only the placeholder was not working as expected.
Then, I found this thread that confirmed that it should work as expected, though it does appear to be broken.
https://forums.modx.com/thread/?thread=96121
This person's simple fix works for me as well, though it looks like it only fixes the placeholder 'object_id'.
If this is simple enough, could you add this in, Bruno?
would you like to show your exported MIGX-configs and your xpdo-schema? I think, there should allready be a way to get what you want.
Sure. Here is my schema
<?xml version="1.0" encoding="UTF-8"?>
<model package="resellers" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.0" phpdoc-package="resellers">
<!-- Extended modUser -->
<object class="extUser" extends="modUser">
<composite alias="ResellerUsers" local="id" class="ResellerUser" foreign="user_id" cardinality="many" owner="local" />
</object>
<!-- Resellers table -->
<object class="Reseller" table="resellers" extends="xPDOSimpleObject">
<field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<!-- general data -->
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="comments" dbtype="text" phptype="string" null="false" default=""/>
<field key="context" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<!-- activity fields -->
<field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
<field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
<field key="editedon" dbtype="datetime" phptype="datetime" null="true"/>
<field key="editedby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
<field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
<!-- relations -->
<composite alias="ResellerUsers" class="ResellerUser" local="id" foreign="reseller_id" cardinality="many" owner="local"/>
<composite alias="Domains" class="Domain" local="id" foreign="reseller_id" cardinality="many" owner="local"/>
<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/>
<aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/>
</object>
<object class="Domain" table="domains" extends="xPDOObject">
<field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<field key="host" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="url" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="reseller_id" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
<field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
<aggregate alias="Reseller" class="Reseller" local="reseller_id" foreign="id" cardinality="one" owner="foreign"/>
</object>
<!-- Reseller / User Pivot -->
<object class="ResellerUser" table="reseller_user" extends="xPDOObject">
<!-- id fields -->
<field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<field key="reseller_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
<field key="user_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
<!-- relations -->
<aggregate alias="Reseller" class="Reseller" local="reseller_id" foreign="id" cardinality="one" owner="foreign"/>
<aggregate alias="User" class="modUser" local="user_id" foreign="id" cardinality="one" owner="foreign"/>
</object>
<!-- Reseller / Resource Pivot -->
<object class="ResellerResource" table="reseller_resource" extends="xPDOObject">
<!-- id fields -->
<field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<field key="reseller_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
<field key="resource_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
<!-- relations -->
<aggregate alias="Reseller" class="Reseller" local="reseller_id" foreign="id" cardinality="one" owner="foreign"/>
<aggregate alias="Resource" class="modResource" local="resource_id" foreign="id" cardinality="one" owner="foreign"/>
</object>
</model>
And here is my migx-config(main)
{
"formtabs":[
{
"MIGX_id":2,
"caption":"General",
"print_before_tabs":"0",
"fields":[
{
"MIGX_id":4,
"field":"name",
"caption":"Name",
"description":"Name of the reseller",
"description_is_code":"0",
"inputTV":"name",
"inputTVtype":"string",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":"0",
"pos":1
},
{
"MIGX_id":5,
"field":"comments",
"caption":"",
"description":"",
"description_is_code":"0",
"inputTV":"comments",
"inputTVtype":"textarea",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":"0",
"pos":2
},
{
"MIGX_id":6,
"field":"id",
"caption":"",
"description":"",
"description_is_code":"0",
"inputTV":"id",
"inputTVtype":"hidden",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":"0",
"pos":3
},
{
"MIGX_id":7,
"field":"context",
"caption":"Context",
"description":"",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"string",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":"0",
"pos":4
}
],
"pos":1
},
{
"MIGX_id":3,
"caption":"Users",
"print_before_tabs":"0",
"fields":[
{
"MIGX_id":8,
"field":"users",
"caption":"Users",
"description":"",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"superboxselect",
"validation":"",
"configs":{
"selectType":"users",
"selectPackage":"resellers"
},
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":1,
"pos":1
}
],
"pos":2
},
{
"MIGX_id":4,
"caption":"Domains",
"print_before_tabs":"0",
"fields":[
{
"MIGX_id":9,
"field":"domains",
"caption":"Domains",
"description":"",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"migxdb",
"validation":"",
"configs":"reseller-domains",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":"0",
"pos":1
}
],
"pos":3
}
],
"contextmenus":"update||recall_remove_delete||remove",
"actionbuttons":"addItem||bulk||toggletrash",
"columnbuttons":"",
"filters":[
{
"MIGX_id":1,
"name":"search",
"label":"search",
"emptytext":"",
"type":"textbox",
"getlistwhere":{
"name:LIKE":"%[[+search]]%",
"OR:description:LIKE":"%[[+search]]%"
},
"getcomboprocessor":"",
"combotextfield":"",
"comboidfield":"",
"combowhere":"",
"comboclassname":"",
"combopackagename":"",
"combo_use_custom_prefix":"0",
"comboprefix":"",
"combojoins":"",
"comboparent":"",
"default":""
}
],
"extended":{
"migx_add":"Add Reseller",
"disable_add_item":"",
"add_items_directly":"",
"formcaption":"",
"update_win_title":"",
"win_id":"",
"maxRecords":"",
"addNewItemAt":"bottom",
"multiple_formtabs":"",
"multiple_formtabs_label":"",
"multiple_formtabs_field":"",
"multiple_formtabs_optionstext":"",
"multiple_formtabs_optionsvalue":"",
"actionbuttonsperrow":4,
"winbuttonslist":"",
"extrahandlers":"",
"filtersperrow":4,
"packageName":"resellers",
"classname":"Reseller",
"task":"",
"getlistsort":"",
"getlistsortdir":"",
"sortconfig":"",
"gridpagesize":"",
"use_custom_prefix":"0",
"prefix":"",
"grid":"",
"gridload_mode":2,
"check_resid":"0",
"check_resid_TV":"",
"join_alias":"",
"has_jointable":"yes",
"getlistwhere":"",
"joins":"",
"hooksnippets":{
"aftergetfields":"getResellerUsers",
"aftersave":"setResellerUsers"
},
"cmpmaincaption":"Resellers",
"cmptabcaption":"All Resellers",
"cmptabdescription":"",
"cmptabcontroller":"",
"winbuttons":"",
"onsubmitsuccess":"",
"submitparams":""
},
"columns":[
{
"MIGX_id":1,
"header":"ID",
"dataIndex":"id",
"width":"",
"sortable":true,
"show_in_grid":1,
"customrenderer":"",
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":"",
"editor":""
},
{
"MIGX_id":2,
"header":"Name",
"dataIndex":"name",
"width":"",
"sortable":"false",
"show_in_grid":1,
"customrenderer":"",
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":"",
"editor":""
},
{
"MIGX_id":3,
"header":"Comments",
"dataIndex":"comments",
"width":"",
"sortable":"false",
"show_in_grid":1,
"customrenderer":"",
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":"",
"editor":""
},
{
"MIGX_id":4,
"header":"Users",
"dataIndex":"users",
"width":"",
"sortable":"false",
"show_in_grid":1,
"customrenderer":"",
"renderer":"this.renderChunk",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"[[migxLoopCollection?\n&packageName=`resellers`\n&classname=`ResellerUser`\n&joins=`[{\"alias\":\"User\"}]`\n&where=`{\"reseller_id\":\"[[+id]]\"}`\n&tpl=`@CODE:<span class=\"x-superboxselect-item\">[[+User_username]]<\/span>`\n&outputSeparator=``\n]]",
"renderoptions":"",
"editor":""
},
{
"MIGX_id":5,
"header":"Domains",
"dataIndex":"rendereddomains",
"width":"",
"sortable":"false",
"show_in_grid":1,
"customrenderer":"",
"renderer":"this.renderChunk",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"[[migxLoopCollection?\n&packageName=`resellers`\n&classname=`Domain`\n&where=`{\"reseller_id\":\"[[+id]]\"}`\n&tpl=`@CODE:<span class=\"x-superboxselect-item\">[[+host]]<\/span>`\n&outputSeparator=``\n]]",
"renderoptions":"",
"editor":""
},
{
"MIGX_id":6,
"header":"Context",
"dataIndex":"context",
"width":"",
"sortable":true,
"show_in_grid":1,
"customrenderer":"",
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":"",
"editor":""
}
]
}
and here is the nested migx-config
{
"formtabs":[
{
"MIGX_id":1,
"caption":"General",
"print_before_tabs":"0",
"fields":[
{
"MIGX_id":1,
"field":"host",
"caption":"http_host",
"description":"The base domain name. (as returned by $_SERVER['HTTP_HOST'])",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"string",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":"0",
"pos":1
},
{
"MIGX_id":2,
"field":"url",
"caption":"site_url",
"description":"The full url, including protocol and sub directory, to the base of the site.",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"string",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":"0",
"pos":2
},
{
"MIGX_id":3,
"field":"reseller_id",
"caption":"reseller ID",
"description":"",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"string",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"none",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"useDefaultIfEmpty":"0",
"pos":3
}
],
"pos":1
}
],
"contextmenus":"update||remove",
"actionbuttons":"addItem",
"columnbuttons":"",
"filters":[
{
"MIGX_id":1,
"name":"sub_search",
"label":"Search",
"emptytext":"",
"type":"textbox",
"getlistwhere":{
"host:LIKE":"%[[+sub_search]]%",
"OR:url:LIKE":"%[[+sub_search]]%"
},
"getcomboprocessor":"",
"combotextfield":"",
"comboidfield":"",
"combowhere":"",
"comboclassname":"",
"combopackagename":"",
"combo_use_custom_prefix":"0",
"comboprefix":"",
"combojoins":"",
"comboparent":"",
"default":""
}
],
"extended":{
"migx_add":"Add Domain",
"disable_add_item":"",
"add_items_directly":"",
"formcaption":"Domains",
"update_win_title":"Domains",
"win_id":"",
"maxRecords":"",
"addNewItemAt":"bottom",
"multiple_formtabs":"",
"multiple_formtabs_label":"",
"multiple_formtabs_field":"",
"multiple_formtabs_optionstext":"",
"multiple_formtabs_optionsvalue":"",
"actionbuttonsperrow":4,
"winbuttonslist":"",
"extrahandlers":"",
"filtersperrow":4,
"packageName":"resellers",
"classname":"Domain",
"task":"",
"getlistsort":"",
"getlistsortdir":"",
"sortconfig":"",
"gridpagesize":"",
"use_custom_prefix":"0",
"prefix":"",
"grid":"",
"gridload_mode":1,
"check_resid":"0",
"check_resid_TV":"",
"join_alias":"",
"has_jointable":"yes",
"getlistwhere":"{\"reseller_id\":[[+object_id]]}",
"joins":"",
"hooksnippets":{
"aftersave":"setDomainReseller"
},
"cmpmaincaption":"Domains",
"cmptabcaption":"domains",
"cmptabdescription":"these are the domains",
"cmptabcontroller":"",
"winbuttons":"",
"onsubmitsuccess":"",
"submitparams":""
},
"columns":[
{
"MIGX_id":2,
"header":"HTTP Host",
"dataIndex":"host",
"width":"",
"sortable":true,
"show_in_grid":1,
"customrenderer":"",
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":"",
"editor":""
},
{
"MIGX_id":3,
"header":"Site URL",
"dataIndex":"url",
"width":"",
"sortable":true,
"show_in_grid":1,
"customrenderer":"",
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":"",
"editor":""
},
{
"MIGX_id":4,
"header":"ID",
"dataIndex":"id",
"width":50,
"sortable":true,
"show_in_grid":1,
"customrenderer":"",
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":"",
"editor":""
}
]
}
The relation I'm talking about is between Reseller and Domain. One reseller has many domains. The second migx is the domains for the particular reseller.