src/ORM/DataObjectSchema.php
protected function checkManyManyFieldClass($parentClass, $component, $joinClass, $specification, $key)
    {
        // Ensure value for this key exists
        if (empty($specification[$key])) {
            throw new InvalidArgumentException(
                "many_many relation {$parentClass}.{$component} has missing {$key} which "
                . "should be a has_one on class {$joinClass}"
            );
        }

        // Check that the field exists on the given object
        $relation = $specification[$key];
        $relationClass = $this->hasOneComponent($joinClass, $relation);
        if (empty($relationClass)) {
            throw new InvalidArgumentException(
                "many_many through relation {$parentClass}.{$component} {$key} references a field name "
                . "{$joinClass}::{$relation} which is not a has_one"
            );
        }

        // Check for polymorphic
        /** @internal Polymorphic many_many is experimental */
        if ($relationClass === DataObject::class) {
            // Currently polymorphic 'from' is supported.
            if ($key === 'from') {
                return $relationClass;
            }
            // @todo support polymorphic 'to'
            throw new InvalidArgumentException(
                "many_many through relation {$parentClass}.{$component} {$key} references a polymorphic field "
                . "{$joinClass}::{$relation} which is not supported"
            );
        }

        // Validate the join class isn't also the name of a field or relation on either side
        // of the relation
        $field = $this->fieldSpec($relationClass, $joinClass);
        if ($field) {
            throw new InvalidArgumentException(
                "many_many through relation {$parentClass}.{$component} {$key} class {$relationClass} "
                . " cannot have a db field of the same name of the join class {$joinClass}"
            );
        }

        // Validate bad types on parent relation
        if ($key === 'from' && $relationClass !== $parentClass) {
            throw new InvalidArgumentException(
                "many_many through relation {$parentClass}.{$component} {$key} references a field name "
                . "{$joinClass}::{$relation} of type {$relationClass}; {$parentClass} expected"
            );
        }
        return $relationClass;
    }
protected function checkManyManyFieldClass($parentClass, $component, $joinClass, $specification, $key)
    {
        // Ensure value for this key exists
        if (empty($specification[$key])) {
            throw new InvalidArgumentException(
                "many_many relation {$parentClass}.{$component} has missing {$key} which "
                . "should be a has_one on class {$joinClass}"
            );
        }

        // Check that the field exists on the given object
        $relation = $specification[$key];
        $relationClass = $this->hasOneComponent($joinClass, $relation);
        if (empty($relationClass)) {
            throw new InvalidArgumentException(
                "many_many through relation {$parentClass}.{$component} {$key} references a field name "
                . "{$joinClass}::{$relation} which is not a has_one"
            );
        }

        // Check for polymorphic
        /** @internal Polymorphic many_many is experimental */
        if ($relationClass === DataObject::class) {
            // Currently polymorphic 'from' is supported.
            if ($key === 'from') {
                return $relationClass;
            }
            // @todo support polymorphic 'to'
            throw new InvalidArgumentException(
                "many_many through relation {$parentClass}.{$component} {$key} references a polymorphic field "
                . "{$joinClass}::{$relation} which is not supported"
            );
        }

        // Validate the join class isn't also the name of a field or relation on either side
        // of the relation
        $field = $this->fieldSpec($relationClass, $joinClass);
        if ($field) {
            throw new InvalidArgumentException(
                "many_many through relation {$parentClass}.{$component} {$key} class {$relationClass} "
                . " cannot have a db field of the same name of the join class {$joinClass}"
            );
        }

        // Validate bad types on parent relation
        if ($key === 'from' && $relationClass !== $parentClass) {
            throw new InvalidArgumentException(
                "many_many through relation {$parentClass}.{$component} {$key} references a field name "
                . "{$joinClass}::{$relation} of type {$relationClass}; {$parentClass} expected"
            );
        }
        return $relationClass;
    }
protected function checkManyManyFieldClass ( $ parentClass , $ component , $ joinClass , $ specification , $ key ) { // Ensure value for this key exists if ( empty ( $ specification [ $ key ] ) ) { throw new InvalidArgumentException ( "many_many relation {$parentClass}.{$component} has missing {$key} which " . "should be a has_one on class {$joinClass}" ) ; } // Check that the field exists on the given object $ relation = $ specification [ $ key ] ; $ relationClass = $ this -> hasOneComponent ( $ joinClass , $ relation ) ; if ( empty ( $ relationClass ) ) { throw new InvalidArgumentException ( "many_many through relation {$parentClass}.{$component} {$key} references a field name " . "{$joinClass}::{$relation} which is not a has_one" ) ; } // Check for polymorphic /** @internal Polymorphic many_many is experimental */ if ( $ relationClass === DataObject :: class ) { // Currently polymorphic 'from' is supported. if ( $ key === 'from' ) { return $ relationClass ; } // @todo support polymorphic 'to' throw new InvalidArgumentException ( "many_many through relation {$parentClass}.{$component} {$key} references a polymorphic field " . "{$joinClass}::{$relation} which is not supported" ) ; } // Validate the join class isn't also the name of a field or relation on either side // of the relation $ field = $ this -> fieldSpec ( $ relationClass , $ joinClass ) ; if ( $ field ) { throw new InvalidArgumentException ( "many_many through relation {$parentClass}.{$component} {$key} class {$relationClass} " . " cannot have a db field of the same name of the join class {$joinClass}" ) ; } // Validate bad types on parent relation if ( $ key === 'from' && $ relationClass !== $ parentClass ) { throw new InvalidArgumentException ( "many_many through relation {$parentClass}.{$component} {$key} references a field name " . "{$joinClass}::{$relation} of type {$relationClass}; {$parentClass} expected" ) ; } return $ relationClass ; }
Validate the to or from field on a has_many mapping class

@param string $parentClass Name of parent class
@param string $component Name of many_many component
@param string $joinClass Class for the joined table
@param array $specification Complete many_many specification
@param string $key Name of key to check ('from' or 'to')

@return string Class that matches the given relation
@throws InvalidArgumentException
Validate the to or from field on a has_many mapping class