We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45290
    • 3 Posts
    gloryofrobots Reply #1, 13 years ago
    Hello. I have two tables "series" and "products". Relationsheep between them - one serie to many products. Of course "products" table has "serie_id? field. In ideal case i need one CMP for series with possibility to go from this CMP to CMP which will show products only for chosen serie. I can do it with custom renderer(column with id and renderer which output is <a href='MANAGER_PATH?a=79&configs=products&serie_id=someId'), but I need possibility to change datagrid search condition programmatically to show products for custom serie. Can i do it? Or may be there is a better way to do it?

    And worst problem for me. For products CMP i create form field whith listbox type and @SELECT binding(@SELECT `name` AS `name`,`id` FROM `[[+PREFIX]]series`), so users can link product to serie. But I can`t find way to show serie name in products CMP, only serie id.
    Thanks for help.

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

    [ed. note: gloryofrobots last edited this post 13 years ago.]
      • 4172
      • 5,888 Posts
      would you like to post your db-schema?

      you can add a listbox-filter to filter the grid by serie
      or you can have a nested MIGXdb-grid in your editor-window, which does only show the related products.

      To show the name in your grid you can add a join into the 'joins' - configuration.
      Need your schema to show the exact syntax for your situation.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 45290
        • 3 Posts
        gloryofrobots Reply #3, 13 years ago
        Thank you, Bruno.
        I created two packages.
        series with schema
        <?xml version="1.0" encoding="UTF-8"?>
        <model package="series" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
        <object class="Serie" table="series" extends="xPDOSimpleObject">
        <!-- specific fields -->
        <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>

        <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" />
        <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>
        </model>

        And products with
        <model package="products" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
        <object class="Product" table="products" extends="xPDOSimpleObject">
        <!-- specific fields. There are lot of fields so I skip all except name and foreign key to series-->
        <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        <field key="serie" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />


        <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" />
        <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>
        </model>
        • discuss.answer
          • 4172
          • 5,888 Posts
          I would put them into one package for example 'gloryofrobotsproducts':

          <?xml version="1.0" encoding="UTF-8"?>
          <model package="gloryofrobotsproducts" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
          <object class="Serie" table="series" extends="xPDOSimpleObject">
          <!-- specific fields -->
          <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
          
          <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" />
          <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"/>
          <composite alias="Products" class="Product" local="id" foreign="serie" cardinality="many" owner="local"/>
          </object>
          
          <object class="Product" table="products" extends="xPDOSimpleObject">
          <!-- specific fields. There are lot of fields so I skip all except name and foreign key to series-->
          <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
          <field key="serie" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
          
          
          <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" />
          <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"/>
          <aggregate alias="Serie" class="Serie" local="serie" foreign="id" cardinality="one" owner="foreign"/>
          
          </object>
          </model> 
          


          put in joins:

          [{"alias":"Serie"}]


          Then you can use 'Serie_name' as fieldname for your column

            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 45290
            • 3 Posts
            gloryofrobots Reply #5, 13 years ago
            Thank you very much. It works.