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

    I've been learning about custom database tables thanks to this amazing article by Bob (http://bobsguides.com/custom-db-tables.html). It's been of great help!

    My question: Can you have one table prefix (as per tutorial) like 'bobs_' with multiple package names. (ie: bobs_quotations, bobs_customers, bobs_orders, etc.)

    My issue: Upon creating my own custom tables the first one I create using the CreateXpdoClasses works just fine (call it gopro_products). However, when I change the myPackage to a different name (customers), it creates issues. Namely, I get class.php files from all tables with the prefix of 'gopro' and the schema file is also picking up data from it as well.

    I hope this question makes sense. Please let me know if further clarification is needed.

    Version: Revolution 2.2.8-pl

    Ben

    This question has been answered by BobRay. See the first response.

    [ed. note: modx125 last edited this post 13 years, 2 months ago.]
    • discuss.answer
      • 3749
      • 24,544 Posts
      Thanks for the kind words. smiley

      I'm not sure I understand your question, but maybe this will help. If you have a bunch of tables that are all part of the same project, it makes sense for them to all have the same table prefix and be part of the same package, but they should probably have a different prefix than the table prefix for other projects, and a different package name. There's no real harm in mixing them together, but if they're separate, addPackage() will load only the classes it needs for the current task.

      The schema is used to create the class and map files for all objects listed in it, and usually it will have only one package. Each object will have its own table (specified in the schema). Once the class and map files have been created, the schema's job is done (in fact, MODX/xPDO ignores it completely during normal operations). addPackage() goes strictly by the path you provide and loads all classes in that path.

      BTW, if you will have intersect tables (aka intersect objects) like customer_orders and order_products (and I think you will), you'll need to manually edit the schema to add aliases for the "related objects" before generating the class and map files. That way, you'll be able to do things like this:

      $customer->getMany('Orders');
      $order->getMany('Products');
      $order->getOne('Customer');
      


      See the Doodles tutorial or the MODX schema (core\model\schema\modx.mysql.schema.xml) for examples. The Articles extra is also a fairly simple example of a package with multiple, related tables. Its schema file is here: core\components\articles\model\schema\articles.mysql.schema.xml
        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
        • 42887
        • 19 Posts
        Quote from: BobRay at Aug 04, 2013, 12:58 AM

        The schema is used to create the class and map files for all objects listed in it, and usually it will have only one package. Each object will have its own table (specified in the schema). Once the class and map files have been created, the schema's job is done (in fact, MODX/xPDO ignores it completely during normal operations). addPackage() goes strictly by the path you provide and loads all classes in that path.

        Thank you for this. I better understand this now and it looks like my addPackage() was the issue. And +1 for the extra materials regarding associated tables...I do indeed have the need for it. I'll be reading through those supplied links when I get to that part. Thanks again!