We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    I have created a custom resource type and I need to store a lot of additional informations to this custom resources in a custom table. The new properties field (since 2.2.x) isn't an option to hold this additional data.

    Does it make sense to extend the custom resource class (like in the RTFM example for extending modUser) and how can this be done? As far as I understand, extending a MODx class results in changed class_key values. Doesn't this interfere with the custom resource class and it's already customized class_key?

    Thanks in advance for your help!
    Martin

    This question has been answered by multiple community members. See the first response.

      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
    • discuss.answer
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      You should probably create a separate object (myCustomResourceData) which you then fetch from the myCustomResource class.

      While technically it is possible to add additional fields to your myCustomResource CRC schema, that will create the additional fields on the site_content table and make a mess of it. So just create a myCustomResourceData class which holds a reference to the resource ID.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 10378
        • 375 Posts
        Quote from: markh at May 19, 2013, 07:22 AM
        ... So just create a myCustomResourceData class which holds a reference to the resource ID.

        This is how I did it Mark!
        I only had to add a plugin (with an OnEmptyTrash listener) which deletes the corresponding data in the myCustomResourceData object if a resource is deleted.

        Thanks!
          Freelancer @bitego http://www.bitego.com
          ---
          GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
          More infos here: http://www.bitego.com/extras/goodnews/
        • discuss.answer
          • 9102 ☆ A M B ☆
          • 318 Posts
          I only had to add a plugin (with an OnEmptyTrash listener) which deletes the corresponding data in the myCustomResourceData object if a resource is deleted.
          Shouldn't that happen automatically if your schema for the custom resource class references your custom table?
            • 10378
            • 375 Posts
            Quote from: esnyder at May 20, 2013, 10:17 AM
            I only had to add a plugin (with an OnEmptyTrash listener) which deletes the corresponding data in the myCustomResourceData object if a resource is deleted.
            Shouldn't that happen automatically if your schema for the custom resource class references your custom table?

            That's why I asked the initial question!
            I think this is only possible, if I extend my custom resource type (like in RTFM modUser extension example). But extending the CRT results in different class_key values which on the other side will break the custom resource type function.

            Or do I understand something wrong?

            Here is my schema for the CRT + the extended object/table:

                <object class="GoodNewsResourceContainer" extends="modResource">
                    <composite alias="ResourceMailing" class="GoodNewsResourceMailing" local="id" foreign="parent" cardinality="many" owner="local" />
                </object>
                
                <object class="GoodNewsResourceMailing" extends="modResource">
                    <aggregate alias="ResourceContainer" class="GoodNewsResourceContainer" local="parent" foreign="id" cardinality="one" owner="foreign" />
                </object>
            
                <object class="GoodNewsMailingMeta" table="goodnews_mailing_meta" extends="xPDOSimpleObject">
                    <field key="mailing_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
                    <field key="groups" dbtype="text" phptype="string" null="false" default="" />
                    <field key="categories" dbtype="text" phptype="string" null="false" default="" />
                    <field key="recipients_list" dbtype="text" phptype="string" null="false" default="" />
                    <field key="test_recipients_list" dbtype="text" phptype="string" null="false" default="" />
                    <field key="recipients_total" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
                    <field key="recipients_sent" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
                    <field key="senton" dbtype="datetime" phptype="datetime" null="true" />
                    <field key="sentby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
                    <field key="finishedon" dbtype="datetime" phptype="datetime" null="true" />
                    <field key="ipc_status" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
                    <aggregate alias="SentBy" class="modUser" local="sentby" foreign="id" cardinality="one" owner="foreign" />
                    <aggregate alias="modResource" class="modResource" local="mailing_id" foreign="id" cardinality="one" owner="foreign" />
                </object>
            


            Do you think I could simply add a composite relation to the GoodNewsResourceMailing object?
            Good thought - I will try this! Thanks!
              Freelancer @bitego http://www.bitego.com
              ---
              GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
              More infos here: http://www.bitego.com/extras/goodnews/
            • discuss.answer
              • 10378
              • 375 Posts
              Quote from: esnyder at May 20, 2013, 10:17 AM
              I only had to add a plugin (with an OnEmptyTrash listener) which deletes the corresponding data in the myCustomResourceData object if a resource is deleted.
              Shouldn't that happen automatically if your schema for the custom resource class references your custom table?

              Success! It works as you told! Just changed the schema and the lines in the extended class are deleted automatically!
              Thanks a lot!

              Here is the new schema:
              (new line 7 + changed line 23)

                  <object class="GoodNewsResourceContainer" extends="modResource">
                      <composite alias="ResourceMailing" class="GoodNewsResourceMailing" local="id" foreign="parent" cardinality="many" owner="local" />
                  </object>
                  
                  <object class="GoodNewsResourceMailing" extends="modResource">
                      <aggregate alias="ResourceContainer" class="GoodNewsResourceContainer" local="parent" foreign="id" cardinality="one" owner="foreign" />
                      <composite alias="MailingMeta" class="GoodNewsMailingMeta" local="id" foreign="mailing_id" cardinality="one" owner="local" />
                  </object>
              
                  <object class="GoodNewsMailingMeta" table="goodnews_mailing_meta" extends="xPDOSimpleObject">
                      <field key="mailing_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
                      <field key="groups" dbtype="text" phptype="string" null="false" default="" />
                      <field key="categories" dbtype="text" phptype="string" null="false" default="" />
                      <field key="recipients_list" dbtype="text" phptype="string" null="false" default="" />
                      <field key="test_recipients_list" dbtype="text" phptype="string" null="false" default="" />
                      <field key="recipients_total" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
                      <field key="recipients_sent" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
                      <field key="senton" dbtype="datetime" phptype="datetime" null="true" />
                      <field key="sentby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
                      <field key="finishedon" dbtype="datetime" phptype="datetime" null="true" />
                      <field key="ipc_status" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
                      <aggregate alias="SentBy" class="modUser" local="sentby" foreign="id" cardinality="one" owner="foreign" />
                      <aggregate alias="ResourceMailing" class="GoodNewsResourceMailing" local="mailing_id" foreign="id" cardinality="one" owner="foreign" />
                  </object>
              
                Freelancer @bitego http://www.bitego.com
                ---
                GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                More infos here: http://www.bitego.com/extras/goodnews/
                • 9102 ☆ A M B ☆
                • 318 Posts
                Yes, that's exactly what I meant, glad it worked out!