We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Quote from: Aalandriel at Oct 21, 2010, 12:52 PM

    on a different note
    The Create Classes snippet will generate classes for all tables with the defined prefix, but is there any built-in functionality to add relations between these tables, or would the schema have to be corrected afterwards? And I guess as a result there of the classes as well?

    Been fiddling with it all day but can’t seem to get it working.

    TBH, I haven’t had time to try it. I kind of suspect that you’d have to put in the aggregate aliases and composite aliases yourself, but at least you’d have a head start with the schema.

    Look at the core/model/schema/modx.mysql.schema.xml file for examples.

    Here are two examples from the modResource class:

    <aggregate alias="Parent" class="modResource" local="parent" foreign="id" cardinality="one" owner="foreign" />
    <aggregate alias="Children" class="modResource" local="id" foreign="parent" cardinality="many" owner="local" />


    alias: How will users refer to this related object
    class: What’s the class of the related object
    local: local key (lkey in this object relating it to the related object)
    foreign: foreign key (key in the related object relating it to this object)
    cardinality: can there be more than one of these related objects that are related to this object
    owner: who owns the key used in the relationship.
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
    • Quote from: BobRay at Oct 21, 2010, 06:28 PM

      owner: which of the two (this or the related object) is higher in the class hierarchy (I’m guessing on this one).
      owner: which of the two (this or the related object) is the owner of the key used in the relationship, the local or foreign

      For example, if we were saving a graph of related objects and the local was being saved with a new instance of a related object that was the owner of the key (foreign from the POV of the object I am saving), the foreign object in this relationship would have to be saved first so the "foreign" key was available to be saved into the local object. This is very important to save() precedence when working with related objects.
        • 818
        • 23 Posts
        Great tutorial, thanks.

        I run the snippets but 3 documents mentioned in the tutorial are not create:
        quotation.class.php
        quotation.map.inc.php
        quotation.class.php

        All the rest is there, what am I missing?

        thanks
          • 3749
          • 24,544 Posts
          Quote from: alaing at Oct 23, 2010, 10:52 PM

          Great tutorial, thanks.

          I run the snippets but 3 documents mentioned in the tutorial are not create:
          quotation.class.php
          quotation.map.inc.php
          quotation.class.php

          All the rest is there, what am I missing?

          thanks


          Was the schema created?
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 3749
            • 24,544 Posts
            Quote from: OpenGeek at Oct 23, 2010, 01:56 PM

            owner: which of the two (this or the related object) is the owner of the key used in the relationship, the local or foreign

            For example, if we were saving a graph of related objects and the local was being saved with a new instance of a related object that was the owner of the key (foreign from the POV of the object I am saving), the foreign object in this relationship would have to be saved first so the "foreign" key was available to be saved into the local object. This is very important to save() precedence when working with related objects.

            This confuses me. Aren’t both keys used in the relationship?
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 818
              • 23 Posts
              Quote from: BobRay at Oct 23, 2010, 11:06 PM

              Quote from: alaing at Oct 23, 2010, 10:52 PM

              Great tutorial, thanks.

              I run the snippets but 3 documents mentioned in the tutorial are not create:
              quotation.class.php
              quotation.map.inc.php
              quotation.class.php

              All the rest is there, what am I missing?

              thanks


              Was the schema created?


              yes it was created :

              <?xml version="1.0" encoding="UTF-8"?>
              <model package="quotation" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
              </model>
                • 3749
                • 24,544 Posts
                That schema is not complete.

                Are you using MODx 1.0.4-pl? It’s required for the script to work.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 818
                  • 23 Posts
                  yes 2.0.4 pl2
                    • 3749
                    • 24,544 Posts
                    Does the table you’re trying to process look normal in the DB (does it have fields and indexes and some content)?
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 20413
                      • 2,877 Posts
                      Sweetnes! Thank you!!
                        @hawproductions | http://mrhaw.com/

                        Infograph: MODX Advanced Install in 7 steps:
                        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower