src/ORM/DataObject.php
protected function mergeRelatedObject($list, $added, $item)
    {
        // Identify item
        $itemKey = get_class($item) . '/' . $item->ID;

        // Write if saved, versioned, and not already added
        if ($item->isInDB() && !isset($list[$itemKey])) {
            $list[$itemKey] = $item;
            $added[$itemKey] = $item;
        }

        // Add joined record (from many_many through) automatically
        $joined = $item->getJoin();
        if ($joined) {
            $this->mergeRelatedObject($list, $added, $joined);
        }
    }
protected function mergeRelatedObject($list, $added, $item)
    {
        // Identify item
        $itemKey = get_class($item) . '/' . $item->ID;

        // Write if saved, versioned, and not already added
        if ($item->isInDB() && !isset($list[$itemKey])) {
            $list[$itemKey] = $item;
            $added[$itemKey] = $item;
        }

        // Add joined record (from many_many through) automatically
        $joined = $item->getJoin();
        if ($joined) {
            $this->mergeRelatedObject($list, $added, $joined);
        }
    }
protected function mergeRelatedObject ( $ list , $ added , $ item ) { // Identify item $ itemKey = get_class ( $ item ) . '/' . $ item -> ID ; // Write if saved, versioned, and not already added if ( $ item -> isInDB ( ) && ! isset ( $ list [ $ itemKey ] ) ) { $ list [ $ itemKey ] = $ item ; $ added [ $ itemKey ] = $ item ; } // Add joined record (from many_many through) automatically $ joined = $ item -> getJoin ( ) ; if ( $ joined ) { $ this -> mergeRelatedObject ( $ list , $ added , $ joined ) ; } }
Merge single object into a list, but ensures that existing objects are not
re-added.

@param ArrayList $list Global list
@param ArrayList $added Additional list to insert into
@param DataObject $item Item to add
Merge single object into a list but ensures that existing objects are not re - added .