We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38666
    • 98 Posts
    I've just spent the evening attempting to get my head around the Dashboard examples of xPDO Schema Files. I think I have got it now but in the process it occurred to me that the author and editor of this section could help other newbies simply by prefixing the foreign keys in the various tables with an 'FK' At the moment they all have the same name (ex blogpost_id) in both the primary and secondary table which is fine once you understand what is going on but but initially it is difficult when trying to understand what goes where.

    Otherwise a great tutorial - Thanks
      Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      I'm not exactly sure what you mean - what exactly is unclear, the way the keys or relations work? Can you maybe provide some snippets of the text/examples of how you would make it clearer?
        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.
        • 38666
        • 98 Posts
        Quote from: markh at Jan 21, 2013, 10:50 PM
        I'm not exactly sure what you mean - what exactly is unclear, the way the keys or relations work? Can you maybe provide some snippets of the text/examples of how you would make it clearer?

        For me and I have since noticed others on this forum making the same comment it is the naming of the fields in the examples for instance
        MySQL Table Definitions	
        CREATE TABLE `blogposts` (
          `blogpost_id` int(11) NOT NULL AUTO_INCREMENT,
          `content` text,
          PRIMARY KEY (`blogpost_id`)
        ) ENGINE=MyISAM;
         
        CREATE TABLE `comments` (
          `comment_id` int(11) NOT NULL AUTO_INCREMENT,
          `blogpost_id` int(11) DEFAULT NULL,
          `comment` text,
          PRIMARY KEY (`comment_id`)
        ) ENGINE=MyISAM;
        


        Here the field `blogpost_id` appears in both the primary and secondary tables. For the newbie such as myself trying to make the leap into PDO it becomes confusing later on
        <composite alias="Comments" class="Comments" local="blogpost_id" foreign="blogpost_id" cardinality="many" owner="local" />
        

        to follow which `blogpost_id` goes where.

        A simple addition in the secondary table like this
        CREATE TABLE `comments` (
          `comment_id` int(11) NOT NULL AUTO_INCREMENT,
          `fk_blogpost_id` int(11) DEFAULT NULL,
          `comment` text,
          PRIMARY KEY (`comment_id`)
        ) ENGINE=MyISAM;
        

        and (if I have it right)
        <composite alias="Comments" class="Comments" local="fk_blogpost_id" foreign="blogpost_id" cardinality="many" owner="local" />
        

        might make one's head spin a bit less slowly (:>)!
          Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Ahh, okay, makes sense.

          Personally I wouldn't make it fk_blogpost_id, but just blogpost, but that's just a personal preference; there's no rules on what you can or cannot name fields in xPDO (as long as it's fine with MySQL tongue). I've updated the docs.
            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.
            • 38666
            • 98 Posts
            Quote from: markh at Jan 22, 2013, 09:17 AM
            Ahh, okay, makes sense.

            Personally I wouldn't make it fk_blogpost_id, but just blogpost, but that's just a personal preference; there's no rules on what you can or cannot name fields in xPDO (as long as it's fine with MySQL tongue). I've updated the docs.

            As you say it is personal preference, but in the case of the tutorial I believe it is less confusing if the fields in the tables do not have the same name.
              Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
              • 38666
              • 98 Posts
              Mark, I just had a look at the docs. Yes that is clearer now. For sake of consistency could you do the same with the Many to Many example too?
              MySQL Table Definitions
              	
              CREATE TABLE `blogposts` (
                `blogpost_id` int(11) NOT NULL AUTO_INCREMENT,
                `content` text,
                PRIMARY KEY (`blogpost_id`)
              ) ENGINE=MyISAM;
               
              CREATE TABLE `tags` (
                `tag_id` int(11) NOT NULL AUTO_INCREMENT,
                `name` varchar(255) DEFAULT NULL,
                PRIMARY KEY (`tag_id`)
              ) ENGINE=MyISAM;
               
              /* The Join Table: */
              CREATE TABLE `blogposts_tags` (
                `id` int(11) NOT NULL AUTO_INCREMENT,
                `blogpost_id` int(11) DEFAULT NULL,
                `tag_id` int(11) DEFAULT NULL,
                PRIMARY KEY (`id`)
              ) ENGINE=MyISAM;
              
                Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                Done 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
                  I like it. I remember being thrown by the fact that the foreign key in the modUserProfile object is called 'internalKey' wink

                    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
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    Quote from: BobRay at Jan 22, 2013, 04:17 PM
                    I like it. I remember being thrown by the fact that the foreign key in the modUserProfile object is called 'internalKey' wink

                    I still don't get why it's called that, lol. Seems kind of random, but then again: naming things is one of the hardest things in development wink
                      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.