We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42511
    • 60 Posts
    Hi,
    Excuse me if this is yet another stupid question.
    I'm attempting to create custom tables(unfortunately there seems to be the necessity for several). I can create the tables by doing a design in MySQL workbench exporting the sql with a few tweeks and uploading it into a local install of Modx, then I can create a schema file by running the script from Bobs' guide or the Modx documentation, and I(probably wrongly) think I almost understand how to add the relationships to the generated schema. However I'd like some of the tables to relate to 'moduser' and to do this, if I understand correctly, I should be extending SPDOSimpleObject rather than just XPDOObject? So the stupid question is this - won't the tables that I created then be incorrect, if XPDOSimpleObject adds an index, or if I know that I should be using XPDOSimpleObject ought I to be creating my initial database tables without a primary key or with some specific key field?
    Thanks
    Allan
      • 3749
      • 24,544 Posts
      That's a really good question. My guess is that you want to create them with an autoincrement primary key called 'id', but I'm not positive.

      I usually extend XPDOSimpleObject, but I don't think whether you do that or use xPDOObject should have a bearing on whether you can have modUser as a related object as long as you specify the custom table's PK in the aliases.

      I don't think you'll have the reciprocal relationship (i.e., the ability to get your custom data objects with $user->getOne() or $user->getMany()) unless you also extend the modUser object, which makes things a little more complicated.

      If all your custom data is user-related, you'd be better off extending modUser to begin with.

        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
        • 42511
        • 60 Posts
        Hi Bob,
        Thanks for the reply. I guess that some of the data is closely user-related and probably ought to extend moduser(though I was trying to avoid it as it looked as though it had further implications), but most of the tables would have the moduser-id as a foreign key. I have to admit I hadn't thought too much about how to retrieve the data(preferring to stay in blissful ignorance for as long as possible and cross that relational bridge when I get to it:-)).
        I'll have a try at creating a table with autoincrement key of 'id' and see how that works. I suppose I could just amend the schema, produce classes, delete the tables I used to create the original schema, then use the amended stuff to recreate the tables?
        Thanks
        Allan
          • 3749
          • 24,544 Posts
          Yes, that all sounds good.

          You might take a look at this: https://github.com/BobRay/ClassExtender. It's an extra I've been working on in my spare time. It's very rough and there are no docs yet, but it extends modUser for you when you install it and creates a custom table for the extra user fields as well as a plugin to add those fields to the Create/Edit User panel in the Manager. Someday, it will get finished and will optionally extend modResource as well.

          As is, it worked for a particular use-case I needed for a client.






            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
            • 42511
            • 60 Posts
            Hi Bob,
            That sounds as though it could be extremely helpful. I'll download it and probably try it when I finish work tomorrow evening - if I can stay awake. Have to go out this evening for a while.
            I'll report back when I've tried it.
            Thanks once again for such excellent assistance.
            regards
            Allan
              • 42511
              • 60 Posts
              Hi,
              Slight delay on the reporting back front. I downloaded the package no problem and tried to alter it to suit what I wanted. First I attempted to build it from outside Modx but I couldn't get that to work. Downloaded and installed MyComponent(what an excellent and useful package you have created there Bob), and managed to build it in that and get the page to display with the fields which I wanted, but the list for the Combo box wasn't populated(this is due to my limited knowledge of programming in Php, I think I'd deleted the wrong curly bracket when I was altering the code). Then I realised that as two of the fields that I'd like to add are going to contain dates it might be useful for them to use the datepicker widget. From reading the Modx documentation for extJS I can see that they need to be defined as datefields - but I can't find any examples of the command format, that demonstrate how to use them on the manager page(I've attempted displaying the dob field in firebug to try and work it out, but I'm not knowledgeable enough to work out the format of the command from the Html that gives me!
              Any pointers as to how to do that would be most welcome.
              Thanks,
              Allan
                • 3749
                • 24,544 Posts
                I don't really know the answer to your question, but the xtypes and the files they are found in are here: http://bobsguides.com/xtype-list.html.

                I'm pretty sure you want datefield as the xtype, so if you search the page for it, you'll see files where it's used and looking at them may help you.
                  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
                  • 42511
                  • 60 Posts
                  Thanks Bob,
                  That's a useful resource that would have saved me some time searching through the manager code if I'd asked earlier smiley I've already furrowed my brow over what's going on in those files and I also had a look at the Sencha documentation. I'll adopt the trial and error approach and let you know if I get it to work.
                  Many thanks for pointing me to your ClassExtender code - it's saved me lots of work and is a huge help towards understanding a little more about how things fit together.
                  regards
                  Allan
                    • 3749
                    • 24,544 Posts
                    Thanks for the kind words. I'm sorry that I haven't had time to finish ClassExtender and create documentation for it. Congratulations on getting it 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