We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Let’s say I have three objects, Listing, Category and ListingCategory

    1. Listing
    	<object class="Listing" table="listing" extends="xPDOSimpleObject">
    		<field key="contact_name" dbtype="varchar" precision="64" phptype="string" null="false" />
    		...
    		<composite alias="ListingCategory" class="ListingCategory" key="listing_id" local="id" 
    foreign="listing_id" cardinality="many" owner="local" />
    	</object>
    


    2. ListingCategory
    	<object class="ListingCategory" table="listing_category" extends="xPDOObject">
    		<field key="listing_id" dbtype="mediumint" precision="10" attributes="unsigned" phptype="integer" null="false" index="pk" />
    		<field key="category_id" dbtype="mediumint" precision="10" attributes="unsigned" phptype="integer" null="false" index="pk" />
    		<aggregate alias="Listing" class="Listing" key="id" local="listing_id" foreign="id" cardinality="one" owner="foreign" />
    		<aggregate alias="Category" class="Category" key="id" local="category_id" foreign="id" cardinality="many" owner="foreign" />
    	</object>
    


    The above relationship seems to work so far for what I’m doing, but it might only be because I don’t have enough data in the tables yet. I’m wondering about the "key" and "foreign" attributes of Listing’s <composite ..> node. How can I define the compound key properly there? I tried comma-separating the keys.. no good.

    Thanks smiley
      Mike Schell
      Lead Developer, MODX Cloud
      Email: [email protected]
      GitHub: https://github.com/netProphET/
      Twitter: @mkschell
      • 26471
      • 17 Posts
      I’m currently attempting the same thing but I’m not having any luck. Can anyone shed some light on how compound aggregate / composite keys can be specified in the schema? Thanks
      • xPDO does not currently handle compound keys automatically, but you can override the xPDOObject functions in your class to make it work, as I did with modResource when accessing modTemplateVar in the Revolution code (as one example).