public function makeDefinition()
    {
        //Find only first level children stored in the same collection
        $children = $this->findChildren(true, true);

        if (empty($children)) {
            //Nothing to inherit
            return $this->schema->getClass();
        }

        //We must sort child in order or unique fields
        uasort($children, [$this, 'sortChildren']);

        //Fields which are common for parent and child models
        $commonFields = $this->schema->getReflection()->getSchema();

        $definition = [];
        foreach ($children as $schema) {
            //Child document fields
            $fields = $schema->getReflection()->getSchema();

            if (empty($fields)) {
                throw new DefinitionException(
                    "Child document '{$schema->getClass()}' of '{$this->schema->getClass()}' does not have any fields"
                );
            }

            $uniqueField = null;
            if (empty($commonFields)) {
                //Parent did not declare any fields, happen sometimes
                $commonFields = $fields;
                $uniqueField = key($fields);
            } else {
                foreach ($fields as $field => $type) {
                    if (!isset($commonFields[$field])) {
                        if (empty($uniqueField)) {
                            $uniqueField = $field;
                        }

                        //New non unique field (must be excluded from analysis)
                        $commonFields[$field] = true;
                    }
                }
            }

            if (empty($uniqueField)) {
                throw new DefinitionException(
                    "Child document '{$schema->getClass()}' of '{$this->schema->getClass()}' does not have any unique field"
                );
            }

            $definition[$uniqueField] = $schema->getClass();
        }

        return $definition;
    }
public function makeDefinition()
    {
        //Find only first level children stored in the same collection
        $children = $this->findChildren(true, true);

        if (empty($children)) {
            //Nothing to inherit
            return $this->schema->getClass();
        }

        //We must sort child in order or unique fields
        uasort($children, [$this, 'sortChildren']);

        //Fields which are common for parent and child models
        $commonFields = $this->schema->getReflection()->getSchema();

        $definition = [];
        foreach ($children as $schema) {
            //Child document fields
            $fields = $schema->getReflection()->getSchema();

            if (empty($fields)) {
                throw new DefinitionException(
                    "Child document '{$schema->getClass()}' of '{$this->schema->getClass()}' does not have any fields"
                );
            }

            $uniqueField = null;
            if (empty($commonFields)) {
                //Parent did not declare any fields, happen sometimes
                $commonFields = $fields;
                $uniqueField = key($fields);
            } else {
                foreach ($fields as $field => $type) {
                    if (!isset($commonFields[$field])) {
                        if (empty($uniqueField)) {
                            $uniqueField = $field;
                        }

                        //New non unique field (must be excluded from analysis)
                        $commonFields[$field] = true;
                    }
                }
            }

            if (empty($uniqueField)) {
                throw new DefinitionException(
                    "Child document '{$schema->getClass()}' of '{$this->schema->getClass()}' does not have any unique field"
                );
            }

            $definition[$uniqueField] = $schema->getClass();
        }

        return $definition;
    }
public function makeDefinition ( ) { //Find only first level children stored in the same collection $ children = $ this -> findChildren ( true , true ) ; if ( empty ( $ children ) ) { //Nothing to inherit return $ this -> schema -> getClass ( ) ; } //We must sort child in order or unique fields uasort ( $ children , [ $ this , 'sortChildren' ] ) ; //Fields which are common for parent and child models $ commonFields = $ this -> schema -> getReflection ( ) -> getSchema ( ) ; $ definition = [ ] ; foreach ( $ children as $ schema ) { //Child document fields $ fields = $ schema -> getReflection ( ) -> getSchema ( ) ; if ( empty ( $ fields ) ) { throw new DefinitionException ( "Child document '{$schema->getClass()}' of '{$this->schema->getClass()}' does not have any fields" ) ; } $ uniqueField = null ; if ( empty ( $ commonFields ) ) { //Parent did not declare any fields, happen sometimes $ commonFields = $ fields ; $ uniqueField = key ( $ fields ) ; } else { foreach ( $ fields as $ field => $ type ) { if ( ! isset ( $ commonFields [ $ field ] ) ) { if ( empty ( $ uniqueField ) ) { $ uniqueField = $ field ; } //New non unique field (must be excluded from analysis) $ commonFields [ $ field ] = true ; } } } if ( empty ( $ uniqueField ) ) { throw new DefinitionException ( "Child document '{$schema->getClass()}' of '{$this->schema->getClass()}' does not have any unique field" ) ; } $ definition [ $ uniqueField ] = $ schema -> getClass ( ) ; } return $ definition ; }
Compile information required to resolve class instance using given set of fields. Fields
based definition will analyze unique fields in every child model to create association
between model class and required set of fields. Only document from same collection will be
involved in definition creation. Definition built only for child of first order.

@return array|string

@throws DefinitionException
Compile information required to resolve class instance using given set of fields . Fields based definition will analyze unique fields in every child model to create association between model class and required set of fields . Only document from same collection will be involved in definition creation . Definition built only for child of first order .