We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14605
    • 40 Posts
    hey I am looking to use xpdo for a custom table structure...

    Are there any examples of single table inheritence that I can use...

    I need to define the following relationship, but can’t find any examples of how to map this into the XML schema (I know hibernate has the "discriminator value" to define inheritance)...

               Item
                |
         --------------
         |            |
      ShopItem     ExternalItem
    
    


    I need to do this to reduce duplicated data in my db. This also allows me to add other types of item easily in the future

    Many thanks

    Jon
      • 22303 MODX Staff
      • 10,725 Posts
      Hello Jon

      MODx Revolution uses single-table inheritance (see the modResource base class and it’s derivatives, modDocument, modStaticResource, modWebLink, and modSymLink), and there is also a sample model (and some unit tests) for single-table inheritance in the xpdo repository’s test/ directory. It all revolves around using the extends attribute in your object element in the schema and having a class_key field in your table.

      You can also look at modElement and it’s derivatives (modScript, modChunk, modTemplateVar, etc.) for a way to accomplish multi-table inheritance, though it does not support cross-table searches or other features so those have to be implemented above and beyond the generated code from the schema.

      If you need further direction, just ask...
        • 14605
        • 40 Posts
        Thanks Jason

        That’s great, I shall feedback my progress as soon as I get some time to work on this, and undoubtedly post some more questions!

        Many thanks

        Jon