We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42049 ☆ A M B ☆
    • 250 Posts
    Flying through MIGXDB now and I love it, however hit a small hurdle that I am hoping some kind soul can help me with.

    I have two tables, a "teams" table (id and name) and a "rosters" table (id, name, teamId e.t.c)

    In my rosters table, I want to via a formtabs selectable option, select the name from the teams table, save the name id to the rosters table, yet render to the user the name.

    I hope this makes sense.

    My scheme file for teams is...
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="teams" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
    	<object class="Team" table="teams" extends="xPDOSimpleObject" >
            <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/> 
    	</object>
    </model>

    And a snippet from my rosters is ...
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="rosters" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
    	<object class="Roster" table="rosters" extends="xPDOSimpleObject">
            <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="teamId" dbtype="tinyint" precision="3" attributes="unsigned" phptype="integer" null="false" />
            
            <aggregate alias="teamName" class="Team" local="teamId" foreign="id" cardinality="one" owner="foreign" />
    	</object>
    </model>


    EDIT :

    I have since looked at this post... https://forums.modx.com/thread/80596/migxdb-cmp-how-to-display-value-from-other-table-in-column

    I have put the following into my MIGX config on the joins table
    [{"alias":"Team"}]

    I have also put Team_name in the formlist selectable with a TV type of "dropdown" but it still doesnt show me any data, and still renders as a text field [ed. note: gelstudios last edited this post 13 years, 6 months ago.]
      GEL STUDIOS
      MODX Professional | MODX Ambassador

      Website | Email | Twitter | Facebook
      • 4172
      • 5,888 Posts
      the name for the 'dropdown'-TV-type is 'listbox'

      and you will need inputOptionValues with an @EVAL or an @SELECT - binding, which fetches the input-options.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 42049 ☆ A M B ☆
        • 250 Posts
        Quote from: Bruno17 at Apr 14, 2013, 07:20 AM
        an @EVAL or an @SELECT - binding, which fetches the input-options.

        Could you provide me a short example of a @eval or @select binding so I can know the syntax to use?

        Is there any documentation to what all these fields mean when adding a form item/column?
          GEL STUDIOS
          MODX Professional | MODX Ambassador

          Website | Email | Twitter | Facebook
          • 33337
          • 3,975 Posts
          Please check this for @SELECT binding: http://rtfm.modx.com/display/revolution20/SELECT+Binding
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
            • 13218
            • 134 Posts
            Hi Graeme,

            in the Input Options / Input Option Value of the listbox TV you could put this to get your listbox data:
            @EVAL return $modx->runSnippet('buildDropDownList');

            and in that snippet you return a string with the list options in the format
            listitem1==listvalue1||listitem1==listvalue2||....

            (maybe item and value the other way around, i keep forgetting the order)

            @SELECT i haven't tried yet.

            Cheers,
            Marc
              @itWilllBeOK
              • 42049 ☆ A M B ☆
              • 250 Posts
              Quote from: zaigham at Apr 14, 2013, 08:05 AM
              Please check this for @SELECT binding: http://rtfm.modx.com/display/revolution20/SELECT+Binding

              Excellent, thats put me on the right track, I now have my names coming through and populating my drop down list.

              To extend this further and to get where I need to be, how do I

              1. - get the ID to be the selected field that get's placed into my rosters table (currently just inputs 0)
              2. - get the name to show in the main columns view

              Thanks again for all the help!
                GEL STUDIOS
                MODX Professional | MODX Ambassador

                Website | Email | Twitter | Facebook
                • 4172
                • 5,888 Posts
                you can try something like that:

                @EVAL return 'choose one==||' . $modx->runSnippet('migxLoopCollection',array('packageName'=>'teams','classname'=>'Team','tpl'=>'@CODE:[[+name]]==[[+id]]','outputSeparator'=>'||'));
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 42049 ☆ A M B ☆
                  • 250 Posts
                  Quote from: Bruno17 at Apr 14, 2013, 09:07 AM
                  you can try something like that:

                  @EVAL return 'choose one==||' . $modx->runSnippet('migxLoopCollection',array('packageName'=>'teams','classname'=>'Team','tpl'=>'@CODE:[[+name]]==[[+id]]','outputSeparator'=>'||'));

                  Your awesome laugh

                  Last step now, how do I get it to display the name instead of the id in the column view? [ed. note: gelstudios last edited this post 13 years, 6 months ago.]
                    GEL STUDIOS
                    MODX Professional | MODX Ambassador

                    Website | Email | Twitter | Facebook
                    • 4172
                    • 5,888 Posts
                    you did this join:

                    [{"alias":"Team"}]


                    right?

                    then you can create a new column with the field: 'Team_name'
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 42049 ☆ A M B ☆
                      • 250 Posts
                      Quote from: Bruno17 at Apr 14, 2013, 09:38 AM
                      column with the field: 'Team_name'

                      I'm guessing after looking at my error log I've missed something in my schema?

                      I'm given this error message

                      No foreign key definition for parentClass: Roster using relation alias: Team
                        GEL STUDIOS
                        MODX Professional | MODX Ambassador

                        Website | Email | Twitter | Facebook