We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Ok, I’m just grooming through the docs and working on my own understanding here.... I’ve got it pretty well down how you can use a MySQL database to generate an xPDO XML schema file, then use that schema file to generate the necessary PHP classes/maps, but how about working this from the other direction?

    1. What if I have an XML schema? How do I generate the database tables?
    2. Is it possible to generate the XML schema given only the PHP map/class files? (That’d be highly unusual, I know, but I’m just wondering if it’s possible).

    Thanks! This will all end up somewhere in the official docs -- I’m working on a spiffy graphic to show this behavior clearly, so please feel free to be as verbose as needed.
      • 28215
      • 4,149 Posts
      Quote from: Everett at Dec 02, 2010, 01:42 AM

      Ok, I’m just grooming through the docs and working on my own understanding here.... I’ve got it pretty well down how you can use a MySQL database to generate an xPDO XML schema file, then use that schema file to generate the necessary PHP classes/maps, but how about working this from the other direction?

      1. What if I have an XML schema? How do I generate the database tables?
      2. Is it possible to generate the XML schema given only the PHP map/class files? (That’d be highly unusual, I know, but I’m just wondering if it’s possible).

      $mgr = $xpdo->getManager():
      $mgr->createObjectContainer('Item');
      $mgr->createObjectContainer('Person');
      $mgr->createObjectContainer('Dog');
      $mgr->createObjectContainer('Treat');
      


      and etc. createObjectContainer creates the table for the class. A lot of times you see me do this in resolvers in the transport packages for custom tables.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Thanks Shaun. So is there a way to iterate through all objects that are defined in an XML body and create *all* the tables? Or do you have to verbosely specify the objects one by one?

          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: Everett at Dec 02, 2010, 10:41 AM

          Thanks Shaun. So is there a way to iterate through all objects that are defined in an XML body and create *all* the tables? Or do you have to verbosely specify the objects one by one?
          A convenience method for creating all the tables in a model package, and a core method for iterating the classes in a model package would both make great feature requests. wink
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            I’m on it. Requesting features: http://bugs.modx.com/issues/2911 This is gonna be so cool...