We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37464
    • 16 Posts
    I have created a MIGX package that (simplified) looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="mikLeaders" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
        <object class="LeaderRole" table="mikLeaderRoles" extends="xPDOSimpleObject">
            <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        </object>
    	<object class="Leader" table="mikLeaders" extends="xPDOSimpleObject">
            <field key="fullname" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        </object>
    	<object class="Assignment" table="mikAssignments" extends="xPDOSimpleObject">
            <field key="leaderid" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="leaderroleid" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" />
        </object>
    </model>


    There is also of course a standard, automatically created, id-field (int) in all the tables. So db is fine, package is fine and I can add and update instances of all three object using CMP.
    My problem is the cmp column for the Assignment object. The assignment object only contains a relation between the id of Leader and the id of Leaderrole but in the grid I would like to see Leader:fullname and Leaderrole:name instead of just their id:s. Which is the recommended way, preferably within the migx cmp configurator, to replace the id:s with the corresponding name/fullname?

    I have tried using this.renderChunk for a dummy column I called leader_mapped with renderChunk Tpl set to
    [[#[[+leaderid]].fullname]]


    leader_mapped column is empty. No errors in the errorlog.

    This is the column setting from edit raw:

    [{"MIGX_id":"1","header":"Ledare","dataIndex":"leaderid","width":"","sortable":"true","show_in_grid":"1","renderer":"","clickaction":"","selectorconfig":"","renderchunktpl":"\t\n","renderoptions":"","editor":""},
    {"MIGX_id":"4","header":"Ledare_mapped","dataIndex":"leader_mapped","width":"","sortable":"false","show_in_grid":"1","renderer":"this.renderChunk","clickaction":"","selectorconfig":"","renderchunktpl":"[[#[[+leaderid]].fullname]]","renderoptions":"","editor":""},
    {"MIGX_id":"2","header":"Roll","dataIndex":"leaderroleid","width":"","sortable":"true","show_in_grid":"1","renderer":"","clickaction":"","selectorconfig":"","renderchunktpl":"","renderoptions":"","editor":""},
    {"MIGX_id":"3","header":"id","dataIndex":"id","width":"","sortable":"false","show_in_grid":"1","renderer":"","clickaction":"","selectorconfig":"","renderchunktpl":"","renderoptions":"","editor":""}]


    I'm using Modx 2.3.3 and MIGX 2.9.3 on modxcloud. pdoTools is installed.

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

    • discuss.answer
      • 4172
      • 5,888 Posts
      fastfield Tags are only working for resources.

      Add relations to your schema:

      <?xml version="1.0" encoding="UTF-8"?>
      <model package="mikLeaders" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
          <object class="LeaderRole" table="mikLeaderRoles" extends="xPDOSimpleObject">
              <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
              <composite alias="Assignments" class="Assignment" local="id" foreign="leaderroleid" cardinality="many" owner="local" />                 
          </object>
          <object class="Leader" table="mikLeaders" extends="xPDOSimpleObject">
              <field key="fullname" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
              <composite alias="Assignments" class="Assignment" local="id" foreign="leaderid" cardinality="many" owner="local" />         
          </object>
          <object class="Assignment" table="mikAssignments" extends="xPDOSimpleObject">
              <field key="leaderid" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" />
              <field key="leaderroleid" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" />
              <aggregate alias="Leader" class="Leader" local="leaderid" foreign="id" cardinality="one" owner="foreign" /> 
              <aggregate alias="LeaderRole" class="LeaderRole" local="leaderroleid" foreign="id" cardinality="one" owner="foreign" /> 
          </object>
      </model>
      


      and parse that schema again.

      It might also be a good idea to make the classnames more unique, for example mikLeaderRole, mikLeader, mikAssignment
      and your tablenames lowercase, like mik_leaders, mik_leader_roles, mik_assignments
      and your packagename also lowercase like mikleaders

      then add joins within the MIGXdb - Settings - tab of the Assignment-MIGX-Configuration:

      [{"alias":"Leader"},{"alias":"LeaderRole"}]


      then you can use Leader_fullname and LeaderRole_name in your columns [ed. note: Bruno17 last edited this post 11 years, 5 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37464
        • 16 Posts
        Quote from: Bruno17 at May 17, 2015, 11:45 PM
        fastfield Tags are only working for resources.

        Add relations to your schema:


        Thank you Bruno - I'll use this approach for the current project. Could you elaborate on why is this a better solution than using this.RenderChunk or maybe a snippet with getObject? Or is it even possible to do what i'm asking for without changing the object model?


          • 4172
          • 5,888 Posts
          with joins, you are getting all fields within one query.
          This is faster, than getting the value for each column at each row with an extra query with renderChunk and getObject

          its also possible todo joins without changing the xpdo-schema

          [{"alias":"Leader","classname":"Leader","on":"Leader.id=leaderid"},{"alias":"LeaderRole","classname":"LeaderRole","on":"LeaderRole.id=leaderroleid"}]


          but its allways a good idea to define aggregate and composite - relationships with the schema.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!