<![CDATA[ Mapping Table Issue - My Forums]]> https://forums.modx.com/thread/?thread=98488 <![CDATA[Mapping Table Issue]]> https://forums.modx.com/thread/98488/mapping-table-issue#dis-post-532685
	<object class="rtPositionCategoriesMap" table="recroot_position_categories_map" extends="xPDOSimpleObject">
		<field key="position_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
		<field key="category_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
		<index alias="category" name="category" primary="false" unique="false" type="BTREE" >
			<column key="category_id" length="" collation="A" null="false" />
		</index>
		<index alias="position" name="position" primary="false" unique="false" type="BTREE" >
			<column key="position_id" length="" collation="A" null="false" />
		</index>
		<aggregate alias="Position" class="rtPositions" local="position_id" foreign="position_id" cardinality="one" owner="foreign" />
		<aggregate alias="Category" class="rtPositionCategories" local="category_id" foreign="positioncategory_id" cardinality="one" owner="foreign" />

	</object>

	<object class="rtPositionCategories" table="recroot_positioncategories" extends="xPDOObject">
		<field key="positioncategory_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />
		<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default="" />

		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
			<column key="positioncategory_id" length="" collation="A" null="false" />
		</index>
		<composite alias="PositionCategories" class="rtPositionCategoriesMap" local="positioncategory_id" foreign="category_id" cardinality="many" owner="local" />
	</object>
	<object class="rtPositions" table="recroot_positions" extends="xPDOObject">
		<field key="position_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />
		<field key="title" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
		<field key="location" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
		<field key="company" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
		<field key="type" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
		<field key="source" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
		<field key="description" dbtype="text" phptype="string" null="false" />
		<field key="applylink" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
		<field key="expireson" dbtype="datetime" phptype="datetime" null="true" />
		<field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
		<field key="featured" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
		<field key="filled" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />

		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
			<column key="position_id" length="" collation="A" null="false" />
		</index>
		<index alias="active" name="active" primary="false" unique="false" type="BTREE" >
			<column key="active" length="" collation="A" null="false" />
		</index>
		<index alias="featured" name="featured" primary="false" unique="false" type="BTREE" >
			<column key="featured" length="" collation="A" null="false" />
		</index>
		<index alias="filled" name="filled" primary="false" unique="false" type="BTREE" >
			<column key="filled" length="" collation="A" null="false" />
		</index>
		<aggregate alias="Type" class="rtPositionTypes" local="type" foreign="positiontype_id" cardinality="one" owner="foreign" />
		<aggregate alias="Company" class="rtCompanies" local="company" foreign="company_id" cardinality="one" owner="foreign" />
		<aggregate alias="Source" class="rtSources" local="source" foreign="source_id" cardinality="one" owner="foreign" />
		<composite alias="PositionCategories" class="rtPositionCategoriesMap" local="position_id" foreign="position_id" cardinality="many" owner="local" />
	</object>


I've been over this so many times I think I'm overlooking something silly. Can anyone see an issue with this?

My snippet call is:
    //get category info
    $pcategories = $position->getMany('PositionCategories');
    $length = count($pcategories);
    error_log("Name: " . $this_title . " Count: " . $length);
    foreach ($pcategories as $pcategory) {
       $this_name = $pcategory->get('name');
       $thisCategoryNames .= $this_name . " ";
       array_push($positionClasses,$this_name);
    }
    error_log("\tCategories Found :" . $thisCategoryNames);//<-- comes back empty



TIA.]]>
harveyev Oct 02, 2015, 07:01 PM https://forums.modx.com/thread/98488/mapping-table-issue#dis-post-532685
<![CDATA[Re: Mapping Table Issue]]> https://forums.modx.com/thread/98488/mapping-table-issue#dis-post-532702 harveyev Oct 03, 2015, 06:38 AM https://forums.modx.com/thread/98488/mapping-table-issue#dis-post-532702 <![CDATA[Re: Mapping Table Issue (Best Answer)]]> https://forums.modx.com/thread/98488/mapping-table-issue#dis-post-532694 rtPositionCategories - items.

you could either create a query with a join and get the items with getCollection.
Maybe there is also a way with getCollectionGraph

or try:

//get category info
$pcategories = $position->getMany('PositionCategories');
$length = count($pcategories);
error_log("Name: " . $this_title . " Count: " . $length);
foreach ($pcategories as $pcategory) {
   if ($category = $pcategory->getOne('Category')){
       $this_name = $category->get('name');
       $thisCategoryNames .= $this_name . " ";
       array_push($positionClasses,$this_name);
   }
}
error_log("\tCategories Found :" . $thisCategoryNames);//<-- comes back empty


to get everything within one joined query might be faster, than calling getOne many times.





]]>
Bruno17 Oct 03, 2015, 12:03 AM https://forums.modx.com/thread/98488/mapping-table-issue#dis-post-532694