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

    I’m trying to use xPDO for an existing database.
    In this database there is one table that is identified by two columns (composite primary key).
    This table needs to be referenced from a different table - and that table of course uses the same two columns (composite foreign key).

    Now I have the following questions:

    • Is this supported by xPDO?
    • How should I define the composite relationship?
      Would this do the trick?: <composite alias="table1" class="myTable1" local="colid1,colid2" foreign="colid1,colid2" cardinality="many" owner="local" />
    • How should I define the aggregate relationship?
      Would this do the trick?: <aggregate alias="table2" class="myTable2" local="colid1,colid2" foreign="colid1,colid2" cardinality="one" owner="foreign" />

    Thanks!
      • 22303 MODX Staff
      • 10,725 Posts
        Quote from: Black at Jun 11, 2010, 10:13 AM

        [list]
      • Is this supported by xPDO?
      • How should I define the composite relationship?
        Would this do the trick?: <composite alias="table1" class="myTable1" local="colid1,colid2" foreign="colid1,colid2" cardinality="many" owner="local" />
      • How should I define the aggregate relationship?
        Would this do the trick?: <aggregate alias="table2" class="myTable2" local="colid1,colid2" foreign="colid1,colid2" cardinality="one" owner="foreign" />
      Though xPDO currently supports tables with compound primary keys, it does not support defining aggregate/composite relationships based on compound keys. For now, you may override xPDOObject methods in these classes to handle the unsupported relation definitions.

      That said, I definitely believe support for this should be added. Can you enter a JIRA feature request for this so I don’t forget to add it to the xPDO roadmap?[/list]
        • 3496
        • 101 Posts
        Ok, it’s a pity, but thanks for the quick response!

        The Jira request: http://svn.modxcms.com/jira/browse/XPDO-55
          • 3496
          • 101 Posts
          Though xPDO currently supports tables with compound primary keys, it does not support defining aggregate/composite relationships based on compound keys. For now, you may override xPDOObject methods in these classes to handle the unsupported relation definitions.
          Could you give me some hint about what methods I would need to override - and what I would need to change?

          Thanks!
            • 22303 MODX Staff
            • 10,725 Posts
            I really depends on the nature of the relationship. You may want to override getOne() or getMany(), depending on the cardinality of the relation, for instance. Since these methods don’t support the multi-column relationship, you could override the behavior when the specific relation’s alias is requested.
              • 3496
              • 101 Posts
              I think I see how I should override getOne and _getRelatedObjectsByFK (for getMany), but it looks as if I also should override xPDOQuery::hydrateGraphNode - but I do not immediately see how to do that, given the fact that it’s part of a different class.
              Any hints?
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: Black at Jun 15, 2010, 01:44 PM

                I think I see how I should override getOne and _getRelatedObjectsByFK (for getMany), but it looks as if I also should override xPDOQuery::hydrateGraphNode - but I do not immediately see how to do that, given the fact that it’s part of a different class.
                Any hints?
                No; that will be part of the support for it; you just need to override getOne() in your class that has the relationship with a compound key until that support is added. You are just going to work around the lack of support for it by overriding the behavior of getOne() when the alias provided matches your relation.