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
    If the class and map files already exist, how would MODX know they are out of date? Comparing them with the schema on every DB access and updating them if necessary would solve your problem, but at a pretty steep price. wink

    BTW, this approach might suit you if the schema is simple enough:

    http://bobsguides.com/custom-db-tables.html

    It will create the schema from the DB tables. It obviously won't create any alias relationships, though.

    Even if it doesn't work to generate the schema, it can be used as a utility to regenerate the class and map files. [ed. note: BobRay last edited this post 9 years, 4 months ago.]
      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
      • 49407
      • 159 Posts
      Quote from: BobRay at Dec 23, 2014, 09:21 PM
      If the class and map files already exist, how would MODX know they are out of date? Comparing them with the schema on every DB access and updating them if necessary would solve your problem, but at a pretty steep price. wink.

      If I were to code such a feature it would be an option in the $modx->getObject and newObject methods.

      You would use $modx->getObject/newObject($classname,,,,true)... the "true" being a trigger to update/create the map. Then you simply remove that one option after you get a successful response. That would eliminate several lines of code needing to be written and removed each time you need to perform an update to a map, or create a new one.

      Set default value to false and it will skip that option unless you need it. No extra cost at all. In fact it would essentially be free. wink
        • 49407
        • 159 Posts
        Quote from: aaronkent at Dec 23, 2014, 09:58 PM
        Quote from: BobRay at Dec 23, 2014, 09:21 PM
        If the class and map files already exist, how would MODX know they are out of date? Comparing them with the schema on every DB access and updating them if necessary would solve your problem, but at a pretty steep price. wink.

        If I were to code such a feature it would be an option in the $modx->getObject and newObject methods.

        You would use $modx->getObject/newObject($classname,,,,true)... the "true" being a trigger to update/create the map. Then you simply remove that one option after you get a successful response. That would eliminate several lines of code needing to be written and removed each time you need to perform an update to a map, or create a new one.

        Set default value to false and it will skip that option unless you need it. No extra cost at all. In fact it would essentially be free. wink

        An even better solution would be to have a feature in the Manager that allowed you to update the maps either all or selectively. I mean there are several better ways to do it that it is done now.
        • I just keep the schema build script in the project's build directory, and quickly run it (open in browser) after making a change smiley
            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.
            • 3749
            • 24,544 Posts
            Quote from: markh at Dec 23, 2014, 11:13 PM
            I just keep the schema build script in the project's build directory, and quickly run it (open in browser) after making a change smiley

            I do the same, but I run it in PhpStorm. It takes about two seconds.
              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
              • 49407
              • 159 Posts
              Does it rebuild all the class schemas or only one specified?

              Seems to me like the one I used (taken from formit2db) builds everything with the prefix you supply, so if all your custom tables have the same prefix it should update them all right?

              Can I get a copy of what you guys use please?
                • 3749
                • 24,544 Posts
                You can get the one I use here: http://bobsguides.com/custom-db-tables.html

                It will do all tables with that prefix, but you also have the option to just edit the schema and create new class and map files. I think you may have to delete the current ones, though it could be modified to just overwrite them. [ed. note: BobRay last edited this post 9 years, 4 months ago.]
                  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
                  • 49407
                  • 159 Posts
                  I've put together a dashboard widget that creates/updates schemas and maps. I based the core code off the code found in FormIt2db with some slign modifications and added a dashboard widget that uses FormIt to pass the data to the hook.

                  I'll post it in a new thread. Thanks for all your help guys.