src/ORM/DataObject.php
public function findRelatedObjects($source, $recursive = true, $list = null)
    {
        if (!$list) {
            $list = new ArrayList();
        }

        // Skip search for unsaved records
        if (!$this->isInDB()) {
            return $list;
        }

        $relationships = $this->config()->get($source) ?: [];
        foreach ($relationships as $relationship) {
            // Warn if invalid config
            if (!$this->hasMethod($relationship)) {
                trigger_error(sprintf(
                    "Invalid %s config value \"%s\" on object on class \"%s\"",
                    $source,
                    $relationship,
                    get_class($this)
                ), E_USER_WARNING);
                continue;
            }

            // Inspect value of this relationship
            $items = $this->{$relationship}();

            // Merge any new item
            $newItems = $this->mergeRelatedObjects($list, $items);

            // Recurse if necessary
            if ($recursive) {
                foreach ($newItems as $item) {
                    /** @var DataObject $item */
                    $item->findRelatedObjects($source, true, $list);
                }
            }
        }
        return $list;
    }
public function findRelatedObjects($source, $recursive = true, $list = null)
    {
        if (!$list) {
            $list = new ArrayList();
        }

        // Skip search for unsaved records
        if (!$this->isInDB()) {
            return $list;
        }

        $relationships = $this->config()->get($source) ?: [];
        foreach ($relationships as $relationship) {
            // Warn if invalid config
            if (!$this->hasMethod($relationship)) {
                trigger_error(sprintf(
                    "Invalid %s config value \"%s\" on object on class \"%s\"",
                    $source,
                    $relationship,
                    get_class($this)
                ), E_USER_WARNING);
                continue;
            }

            // Inspect value of this relationship
            $items = $this->{$relationship}();

            // Merge any new item
            $newItems = $this->mergeRelatedObjects($list, $items);

            // Recurse if necessary
            if ($recursive) {
                foreach ($newItems as $item) {
                    /** @var DataObject $item */
                    $item->findRelatedObjects($source, true, $list);
                }
            }
        }
        return $list;
    }
public function findRelatedObjects ( $ source , $ recursive = true , $ list = null ) { if ( ! $ list ) { $ list = new ArrayList ( ) ; } // Skip search for unsaved records if ( ! $ this -> isInDB ( ) ) { return $ list ; } $ relationships = $ this -> config ( ) -> get ( $ source ) ? : [ ] ; foreach ( $ relationships as $ relationship ) { // Warn if invalid config if ( ! $ this -> hasMethod ( $ relationship ) ) { trigger_error ( sprintf ( "Invalid %s config value \"%s\" on object on class \"%s\"" , $ source , $ relationship , get_class ( $ this ) ) , E_USER_WARNING ) ; continue ; } // Inspect value of this relationship $ items = $ this -> { $ relationship } ( ) ; // Merge any new item $ newItems = $ this -> mergeRelatedObjects ( $ list , $ items ) ; // Recurse if necessary if ( $ recursive ) { foreach ( $ newItems as $ item ) { /** @var DataObject $item */ $ item -> findRelatedObjects ( $ source , true , $ list ) ; } } } return $ list ; }
Find objects in the given relationships, merging them into the given list

@param string $source Config property to extract relationships from
@param bool $recursive True if recursive
@param ArrayList $list If specified, items will be added to this list. If not, a new
instance of ArrayList will be constructed and returned
@return ArrayList The list of related objects
Find objects in the given relationships merging them into the given list