src/Model/AssociationsAwareTrait.php
private function setByTypeModuleField(string $module, CsvField $field) : void
    {
        // skip non related type
        if (! $this->isRelatedType($field)) {
            return;
        }

        // skip associations between other modules
        if (! in_array($this->getTableName(), [$module, $field->getAssocCsvModule()])) {
            return;
        }

        $className = '';
        $associationType = '';

        /**
         * for current table instance "Articles", assuming that the provide $module is "Articles" and
         * a field "author_id" of type "related(Authors)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $articlesTable->belongTo('AuthorIdAuthors', ['className' => 'Authors', 'foreignKey' => 'author_id']);
         */
        if ($this->getTableName() === $module) {
            $className = $field->getAssocCsvModule();
            $associationType = 'belongsTo';
        }

        /**
         * for current table instance "Authors", assuming that the provide $module is "Articles" and
         * a field "related_author" of type "related(Authors)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $authorsTable->hasMany('RelatedAuthorArticles', ['className' => 'Articles', 'foreignKey' => 'related_author']);
         */
        if ($this->getTableName() === $field->getAssocCsvModule()) {
            $className = $module;
            $associationType = 'hasMany';
        }

        /**
         * for current table instance "Articles", assuming that the provide $module is "Articles" and
         * a field "main_article" of type "related(Articles)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $articlesTable->belongTo('MainArticleArticles', ['className' => 'Articles', 'foreignKey' => 'main_article']);
         */
        if ($field->getAssocCsvModule() === $module) {
            $className = $module;
            $associationType = 'belongsTo';
        }

        $this->setAssociation(
            $associationType,
            static::generateAssociationName($className, $field->getName()),
            ['className' => $className, 'foreignKey' => $field->getName()]
        );
    }
private function setByTypeModuleField(string $module, CsvField $field) : void
    {
        // skip non related type
        if (! $this->isRelatedType($field)) {
            return;
        }

        // skip associations between other modules
        if (! in_array($this->getTableName(), [$module, $field->getAssocCsvModule()])) {
            return;
        }

        $className = '';
        $associationType = '';

        /**
         * for current table instance "Articles", assuming that the provide $module is "Articles" and
         * a field "author_id" of type "related(Authors)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $articlesTable->belongTo('AuthorIdAuthors', ['className' => 'Authors', 'foreignKey' => 'author_id']);
         */
        if ($this->getTableName() === $module) {
            $className = $field->getAssocCsvModule();
            $associationType = 'belongsTo';
        }

        /**
         * for current table instance "Authors", assuming that the provide $module is "Articles" and
         * a field "related_author" of type "related(Authors)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $authorsTable->hasMany('RelatedAuthorArticles', ['className' => 'Articles', 'foreignKey' => 'related_author']);
         */
        if ($this->getTableName() === $field->getAssocCsvModule()) {
            $className = $module;
            $associationType = 'hasMany';
        }

        /**
         * for current table instance "Articles", assuming that the provide $module is "Articles" and
         * a field "main_article" of type "related(Articles)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $articlesTable->belongTo('MainArticleArticles', ['className' => 'Articles', 'foreignKey' => 'main_article']);
         */
        if ($field->getAssocCsvModule() === $module) {
            $className = $module;
            $associationType = 'belongsTo';
        }

        $this->setAssociation(
            $associationType,
            static::generateAssociationName($className, $field->getName()),
            ['className' => $className, 'foreignKey' => $field->getName()]
        );
    }
private function setByTypeModuleField ( string $ module , CsvField $ field ) : void { // skip non related type if ( ! $ this -> isRelatedType ( $ field ) ) { return ; } // skip associations between other modules if ( ! in_array ( $ this -> getTableName ( ) , [ $ module , $ field -> getAssocCsvModule ( ) ] ) ) { return ; } $ className = '' ; $ associationType = '' ; /**
         * for current table instance "Articles", assuming that the provide $module is "Articles" and
         * a field "author_id" of type "related(Authors)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $articlesTable->belongTo('AuthorIdAuthors', ['className' => 'Authors', 'foreignKey' => 'author_id']);
         */ if ( $ this -> getTableName ( ) === $ module ) { $ className = $ field -> getAssocCsvModule ( ) ; $ associationType = 'belongsTo' ; } /**
         * for current table instance "Authors", assuming that the provide $module is "Articles" and
         * a field "related_author" of type "related(Authors)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $authorsTable->hasMany('RelatedAuthorArticles', ['className' => 'Articles', 'foreignKey' => 'related_author']);
         */ if ( $ this -> getTableName ( ) === $ field -> getAssocCsvModule ( ) ) { $ className = $ module ; $ associationType = 'hasMany' ; } /**
         * for current table instance "Articles", assuming that the provide $module is "Articles" and
         * a field "main_article" of type "related(Articles)" is found in its migration.json config,
         * then we set the association as follows:
         *
         * $articlesTable->belongTo('MainArticleArticles', ['className' => 'Articles', 'foreignKey' => 'main_article']);
         */ if ( $ field -> getAssocCsvModule ( ) === $ module ) { $ className = $ module ; $ associationType = 'belongsTo' ; } $ this -> setAssociation ( $ associationType , static :: generateAssociationName ( $ className , $ field -> getName ( ) ) , [ 'className' => $ className , 'foreignKey' => $ field -> getName ( ) ] ) ; }
Set associations by field, for "module" type Modules.

@param string $module Module name
@param \CsvMigrations\FieldHandlers\CsvField $field CSV Field instance
@return void
Set associations by field for module type Modules .