src/ORM/DataObject.php
public function getComponents($componentName, $id = null)
    {
        if (!isset($id)) {
            $id = $this->ID;
        }
        $result = null;

        $schema = $this->getSchema();
        $componentClass = $schema->hasManyComponent(static::class, $componentName);
        if (!$componentClass) {
            throw new InvalidArgumentException(sprintf(
                "DataObject::getComponents(): Unknown 1-to-many component '%s' on class '%s'",
                $componentName,
                static::class
            ));
        }

        // If we haven't been written yet, we can't save these relations, so use a list that handles this case
        if (!$id) {
            if (!isset($this->unsavedRelations[$componentName])) {
                $this->unsavedRelations[$componentName] =
                    new UnsavedRelationList(static::class, $componentName, $componentClass);
            }
            return $this->unsavedRelations[$componentName];
        }

        // Determine type and nature of foreign relation
        $joinField = $schema->getRemoteJoinField(static::class, $componentName, 'has_many', $polymorphic);
        /** @var HasManyList $result */
        if ($polymorphic) {
            $result = PolymorphicHasManyList::create($componentClass, $joinField, static::class);
        } else {
            $result = HasManyList::create($componentClass, $joinField);
        }

        return $result
            ->setDataQueryParam($this->getInheritableQueryParams())
            ->forForeignID($id);
    }
public function getComponents($componentName, $id = null)
    {
        if (!isset($id)) {
            $id = $this->ID;
        }
        $result = null;

        $schema = $this->getSchema();
        $componentClass = $schema->hasManyComponent(static::class, $componentName);
        if (!$componentClass) {
            throw new InvalidArgumentException(sprintf(
                "DataObject::getComponents(): Unknown 1-to-many component '%s' on class '%s'",
                $componentName,
                static::class
            ));
        }

        // If we haven't been written yet, we can't save these relations, so use a list that handles this case
        if (!$id) {
            if (!isset($this->unsavedRelations[$componentName])) {
                $this->unsavedRelations[$componentName] =
                    new UnsavedRelationList(static::class, $componentName, $componentClass);
            }
            return $this->unsavedRelations[$componentName];
        }

        // Determine type and nature of foreign relation
        $joinField = $schema->getRemoteJoinField(static::class, $componentName, 'has_many', $polymorphic);
        /** @var HasManyList $result */
        if ($polymorphic) {
            $result = PolymorphicHasManyList::create($componentClass, $joinField, static::class);
        } else {
            $result = HasManyList::create($componentClass, $joinField);
        }

        return $result
            ->setDataQueryParam($this->getInheritableQueryParams())
            ->forForeignID($id);
    }
public function getComponents ( $ componentName , $ id = null ) { if ( ! isset ( $ id ) ) { $ id = $ this -> ID ; } $ result = null ; $ schema = $ this -> getSchema ( ) ; $ componentClass = $ schema -> hasManyComponent ( static :: class , $ componentName ) ; if ( ! $ componentClass ) { throw new InvalidArgumentException ( sprintf ( "DataObject::getComponents(): Unknown 1-to-many component '%s' on class '%s'" , $ componentName , static :: class ) ) ; } // If we haven't been written yet, we can't save these relations, so use a list that handles this case if ( ! $ id ) { if ( ! isset ( $ this -> unsavedRelations [ $ componentName ] ) ) { $ this -> unsavedRelations [ $ componentName ] = new UnsavedRelationList ( static :: class , $ componentName , $ componentClass ) ; } return $ this -> unsavedRelations [ $ componentName ] ; } // Determine type and nature of foreign relation $ joinField = $ schema -> getRemoteJoinField ( static :: class , $ componentName , 'has_many' , $ polymorphic ) ; /** @var HasManyList $result */ if ( $ polymorphic ) { $ result = PolymorphicHasManyList :: create ( $ componentClass , $ joinField , static :: class ) ; } else { $ result = HasManyList :: create ( $ componentClass , $ joinField ) ; } return $ result -> setDataQueryParam ( $ this -> getInheritableQueryParams ( ) ) -> forForeignID ( $ id ) ; }
Returns a one-to-many relation as a HasManyList

@param string $componentName Name of the component
@param int|array $id Optional ID(s) for parent of this relation, if not the current record
@return HasManyList|UnsavedRelationList The components of the one-to-many relationship.
Returns a one - to - many relation as a HasManyList