Index: t3lib/class.t3lib_loaddbgroup.php =================================================================== --- t3lib/class.t3lib_loaddbgroup.php (Revision 9766) +++ t3lib/class.t3lib_loaddbgroup.php (Arbeitskopie) @@ -92,6 +92,7 @@ var $MM_match_fields = array(); // array of fields value pairs that should match while SELECT and will be written into MM table if $MM_insert_fields is not set var $MM_insert_fields = array(); // array of fields and value pairs used for insert in MM table var $MM_table_where = ''; // extra MM table where + var $foreignField; // the foreign field /** * @var boolean @@ -167,6 +168,8 @@ next($this->tableArray); $this->secondTable = key($this->tableArray); // If the second table is set and the ID number is less than zero (later) then the record is regarded to come from the second table... + // Set the foreignField to use is later to update the count + $this->foreignField = $conf['foreign_field']; // Now, populate the internal itemArray and tableArray arrays: if ($MMtable) { // If MM, then call this function to do that: if ($MMuid) { @@ -441,6 +444,20 @@ $this->updateRefIndex($val['table'], $val['id']); } } + + // count the relations + $whereClause = $uidForeign_field . ' = ' . intval($val['id']); + $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $MM_tableName, $whereClause); + $whereClause = 'uid = ' . intval($val['id']); + + if ($this->MM_is_foreign) { + // update the value of the foreign table + $whereClause = 'uid = ' . intval($val['id']); + $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->MM_oppositeTable, $whereClause, array($this->MM_oppositeField => $count)); + } else { + // update the value for this table + $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tablename, $whereClause, array($this->foreignField => $count)); + } } // Delete all not-used relations: