Issues using migxdb to extend modUser

I am trying to use migxdb to extend the modUser class with additional fields. (I can’t use extended fields for various reasons)

What did I do?

  • created custom package with some additional fields
  • created migxdb config on a cmp for modUser class
    => works
  • added join for this migxdb [{"alias":"Extended","classname":"user_introtextList","on":"modUser.id = user_introtextList.user_id"}]
    => Then I can select the joined columns, but loading the CMP thereafter fails.

Error log:

mgr/smarty/default/0e3972b87c915e32a04892a8ac4da1507f059093_0.file.gridpanel.tpl.php : 69) PHP warning: Undefined array key "customHandlers"
mgr/smarty/default/0e3972b87c915e32a04892a8ac4da1507f059093_0.file.gridpanel.tpl.php : 69) PHP warning: Attempt to read property "value" on null

What am I doing wrong?

I basically want to achieve the following:

  • display modUser with additional fields joined from my custom package on a CMP
  • edit those additional fields via the CMP

Thanks in advance!

Can you provide more information, like the schema you are using and the MIGX config (Right-click on config → “Export/Import” → copy the JSON).

Also, are you using MODX 2.x or 3.x?


Instead of migxDB, you could also use one these other extras to extend modUser:

Thanks for suggesting those two packages, but I guess those won’t work since we want to add some migx configs insides those additional fields. (e.g. downloads)

<?xml version="1.0" encoding="UTF-8"?>

<model package="ahs" baseClass="xPDOObject" platform="mysql" defaultEngine="InnoDB" phpdoc-package="" phpdoc-subpackage="" version="1.1">
  <object class="ahsUser" table="ahs_users" extends="xPDOSimpleObject">
    <field key="user_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"  />

    <field key="title" dbtype="varchar" phptype="string" precision="255" null="false" default="" />
    <field key="description" dbtype="text" phptype="string" null="false" default=""  />
    <field key="downloads" dbtype="text" phptype="string" null="false" default=""  />

    <aggregate alias="User" class="modUser" local="user_id" foreign="id" cardinality="one" owner="foreign" />

    <index alias="user_id" name="user_id" primary="false" unique="false" type="BTREE">
      <column key="user_id" length="" collation="A" null="false" />
    </index>
  </object>
</model>
{
  "formtabs":"",
  "contextmenus":"",
  "actionbuttons":"",
  "columnbuttons":"",
  "filters":"",
  "extended":{
    "migx_add":"",
    "disable_add_item":"",
    "add_items_directly":"",
    "formcaption":"",
    "update_win_title":"",
    "win_id":"",
    "maxRecords":"",
    "addNewItemAt":"bottom",
    "media_source_id":"",
    "multiple_formtabs":"",
    "multiple_formtabs_label":"",
    "multiple_formtabs_field":"",
    "multiple_formtabs_optionstext":"",
    "multiple_formtabs_optionsvalue":"",
    "actionbuttonsperrow":4,
    "winbuttonslist":"",
    "extrahandlers":"",
    "filtersperrow":4,
    "packageName":"",
    "classname":"modUser",
    "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":"Ahs",
        "classname":"ahsUser",
        "on":"modUser.id = ahsUser.user_id"
      }
    ],
    "hooksnippets":"",
    "cmpmaincaption":"",
    "cmptabcaption":"",
    "cmptabdescription":"",
    "cmptabcontroller":"",
    "winbuttons":"",
    "onsubmitsuccess":"",
    "submitparams":""
  },
  "permissions":{
    "apiaccess":"",
    "view":"",
    "list":"",
    "save":"",
    "create":"",
    "remove":"",
    "delete":"",
    "publish":"",
    "unpublish":"",
    "viewdeleted":"",
    "viewunpublished":""
  },
  "fieldpermissions":"",
  "columns":[
    {
      "MIGX_id":2,
      "dataIndex":"id",
      "header":"id"
    },
    {
      "MIGX_id":3,
      "dataIndex":"username",
      "header":"username"
    },
    {
      "MIGX_id":5,
      "dataIndex":"Ahs_title",
      "header":"Ahs_title"
    }
  ],
  "category":""
}

Use the alias in the join condition:

"joins":[
      {
        "alias":"Ahs",
        "classname":"ahsUser",
        "on":"modUser.id = Ahs.user_id"
      }
    ],

Add the name of your custom package, so that MIGX loads it and your custom class is known.

"packageName":"ahs",

With this changes you should be able to read the data from your custom table.
To write data to your custom table, you probably have to write an aftersave-hook snippet.

Oh boy…I confused the alias in the join condition. :sweat_smile: That does the trick. Thanks a lot. :pray:

So to write data I will just configure formtabs with the desired input types for the additional fields and then handle the actual creation/update with an aftersave-hook, correct?

Will give it a try.

I think so.
There is an example hook snippet on this site (that uses modProfile instead of a custom class).