We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20707
    • 42 Posts
    Hello,

    I've read most of the documentation on MODx and found it to be very insightful. However, the one thing that documentation can't inform you about is, how to design your own business model layer. For instance, I am in the process of building my own movie review site. I will be mashing up several JSON APIs from the leading online movie review platforms. I can integrate a lot of the time sensitive material such as "Latest Movies", etc..... using node.js, etc..... However, I do need a base layer of content for SEO purposes. Anyway, to make a long story short. Here is what I need:

    A practical way to extend MODx with my own proprietary DB model/tables without sacrificing access to the Modx core DB objects and classes. After reading over the documentation, I believe I would probably start with extending modResource with my own base class. The problem is, how do I integrate the site_content table with my own tables?

    I have attached a screen shot of the beginning (not complete by any means) structure of my DB tables and relationships. If someone could tell me the best approach to extending Modx with my design without sacrificing the use of the modx core objects and classes, I'd realy appreciate it.

    In a solid relational model, there are quite a few "lookup or join" tables and I don't see how I could fit that in with Modx. For instance, I have an object called Movie, Category and Person. So, do I have to put all of these entries in the site_content table then use lookup tables to join them back to the same table? Maybe, get rid of the join tables and use JSON instead?

    I'm not quite sure and need some solid advice. Please see the attached screen shot of the beginnings of my relational model.

    Regards,
    Matt
      • 33968
      • 863 Posts
      Hey Matt

      What you want to do is very achievable in MODX Revolution. It would be a good idea to spend a bit of time reading through the docs on xPDO:

      http://rtfm.modx.com/display/xPDO20/Home

      Check out parts 1 and 2 of the following tutorial to get an idea of how to set up your custom database model within MODX and build a basic manager page:

      http://rtfm.modx.com/display/revolution20/Developing+an+Extra+in+MODX+Revolution

      I'm sure you'll have some questions so feel free to post back here...
        • 20707
        • 42 Posts
        Hi Lucas,

        Thank you for taking the time to respond. I've read over those documents pretty thoroughly. My question is mainly about DB architecture that will integrate will with the existing Modx schema. However, I am sure I missed some things and will have a look at these again.

        Thanks again Lucas.
          • 3749
          • 24,544 Posts
          muzikman, it's not necessarily about integrating with the MODX schema. You can create your own schema, create and load your own object classes, and use xPDO to interact with the DB.

          In your case, I don't think you'd want to carry the overhead of a resource (or other MODX object) for each movie at your site. You could create tables as you've pictured them, use xPDO for the DB layer, and write your own CRUD code with xPDO.

          If would be very handy to be able to use xPDO methods like getObject(), getOne(), and getMany() with your DB and do xPDO queries on it, but you don't need to subclass any MODX objects to do that. There's some info here on using custom tables: http://bobsguides.com/custom-db-tables.html. The method there won't work for you because you have many-to-many relationships, but it might give you some ideas and the links at the bottom of the page are useful.


          The only advantage of piggy-backing on the MODX schema is if you want to use existing MODX extras like getResources to display results, and I don't think you need that.



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            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
            • 20707
            • 42 Posts
            Hi Bob,

            Thank you for the information. I have already been to your site and read over just about every article on Modx. It has really made my transition that much easier from the Joomla/Drupal world to Modx. I just wanted to take a brief moment to thank you.

            I just spent quite a few hours looking over the tutorials on Xpdo and I arrived at the same conclusion as you. You are correct, the reason I wanted to extend the modResource class is to use the many add ons that integrate with that table.

            There is no way I could utilize the site_content with my scheme as you mentioned. I mean, put either one or both of the movie and people documents in the resources table? That would be ridiculous and defies all good ORMs.

            I think I will continue to work on my database design. Then, use Migx or CMP to generate the scheme from my tables. Then, build the class maps and model, etc..... Finally, the manager pages.

            I was just thinking. Why not just build a site using Xpdo without Modx? smiley


            Thanks for your insight. It's been a big help.

            Matt
              • 3749
              • 24,544 Posts
              You could certainly build the site without MODX. You'd have to create your own UI to interact with the DB, but it sounds like you're going to have to do that anyway. It would certainly give you snappier performance when entering and editing your data.

              You could also just do it with TVs and Migx - the advantage there would be quick development at the possible cost of performance and scalability.



              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html
                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
                • 4172
                • 5,888 Posts
                I think I will continue to work on my database design. Then, use Migx or CMP to generate the scheme from my tables. Then, build the class maps and model, etc..... Finally, the manager pages.
                I'm sure it would be possible to put the whole thing together with help of MIGXdb for the CMP

                you could have three tabs Persons/Movies/Genres

                when you are editing Persons there could be another MIGXdb - TV where you get the grid for searching/adding/activating Movies which are related to the Person.

                The same for Movies/Persons and Movies/Genres Genres/Movies

                If you need a category-tree, where Movies belong to multiple categories, it would be possible to create the categories by the Resource-tree and have MIGXdb-TVs with Movies in it to create the Relations between Categories/Movies.

                Just some ideas [ed. note: Bruno17 last edited this post 14 years, 4 months ago.]
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 3548
                  • 102 Posts
                  From my experience, do your own xpdo schema. When that is set up, CRUD part is basically done. Also, do your own CMP. It is very rewarding approach and when you build few things like this you will never look back again...
                    Antonio Zdilar
                    linearvector.com
                    • 20707
                    • 42 Posts
                    Thanks for all of the input. It's much appreciated. Some interesting ideas. I was also looking into other ORM frameworks (Zend, Symphony, Prospect) and entertaining that as well. As Bob mentioned, yes, I would have to build my own UI and that is something that I would dread. However, I basically have to do that in the Modx manager anyway.

                    My only other concern is, the ability to use third party add ons such as Quip. I will need a commenting system and that would have to be modified to point to my movie table instead of the site_content table, etc......

                    The MigxDB approach might be a possibility for something short term and quick. but for a long term solution, I would much rather join the relationships on true integer based indexes. Using JSON for extra data in a table is fine but to create relationships, I wouldn't feel comfortable with it long term.

                    I think I will try a few different approaches. First thing, I need to develop my DB model and that's what I'm currently working on, regardless of the platform I choose ultimately.
                      • 20707
                      • 42 Posts
                      If I were to use Xpdo without Modx, not only would I have to build my own UI, I would also have to tie that into an ACL and that is a lot of work. I will have editor, reviewer groups, etc...

                      Another thing I need to consider are all of the other Movie relationships such as, alternate titles, spoken languages, production companies, etc...... There would be no possible way to manage 100k movies with the current Modx tree system. It would be a nightmare to work with and I'm sure Modx wouldn't be able to handle the overhead. It would definitely have to be implemented using lookup search element.

                      I love Modx and will definitely use it either for this project or for just a general purpose CMS. [ed. note: muzikman last edited this post 14 years, 4 months ago.]