original_string: private function isManyToMany($tables, $tableName, $modelTable, $modelTableName)
      {
          // get table details
          $table = $tables[$tableName];
  
          $isAnyKeyOnModelTable = false;
  
          // many to many model table name
          $manyToManyTable = '';
  
          $foreignKeys = $table->foreignKeys;
          $primary = $table->primaryKey;
  
          // check if any foreign key is there from model table
          foreach ($foreignKeys as $foreignKey) {
              if ($foreignKey->foreignTable == $modelTableName) {
                  $isAnyKeyOnModelTable = true;
              }
          }
  
          // if foreign key is there
          if ($isAnyKeyOnModelTable) {
              foreach ($foreignKeys as $foreignKey) {
                  $foreignField = $foreignKey->foreignField;
                  $foreignTableName = $foreignKey->foreignTable;
  
                  // if foreign table is model table
                  if ($foreignTableName == $modelTableName) {
                      $foreignTable = $modelTable;
                  } else {
                      $foreignTable = $tables[$foreignTableName];
                      // get the many to many model table name
                      $manyToManyTable = $foreignTableName;
                  }
  
                  // if foreign field is not primary key of foreign table
                  // then it can not be many to many
                  if ($foreignField != $foreignTable->primaryKey) {
                      return false;
                      break;
                  }
  
                  // if foreign field is primary key of this table
                  // then it can not be many to many
                  if ($foreignField == $primary) {
                      return false;
                  }
              }
          }
  
          $modelName = model_name_from_table_name($manyToManyTable);
  
          return GeneratorFieldRelation::parseRelation('mtm,'.$modelName.','.$tableName);
      }
code: private function isManyToMany($tables, $tableName, $modelTable, $modelTableName)
      {
          // get table details
          $table = $tables[$tableName];
  
          $isAnyKeyOnModelTable = false;
  
          // many to many model table name
          $manyToManyTable = '';
  
          $foreignKeys = $table->foreignKeys;
          $primary = $table->primaryKey;
  
          // check if any foreign key is there from model table
          foreach ($foreignKeys as $foreignKey) {
              if ($foreignKey->foreignTable == $modelTableName) {
                  $isAnyKeyOnModelTable = true;
              }
          }
  
          // if foreign key is there
          if ($isAnyKeyOnModelTable) {
              foreach ($foreignKeys as $foreignKey) {
                  $foreignField = $foreignKey->foreignField;
                  $foreignTableName = $foreignKey->foreignTable;
  
                  // if foreign table is model table
                  if ($foreignTableName == $modelTableName) {
                      $foreignTable = $modelTable;
                  } else {
                      $foreignTable = $tables[$foreignTableName];
                      // get the many to many model table name
                      $manyToManyTable = $foreignTableName;
                  }
  
                  // if foreign field is not primary key of foreign table
                  // then it can not be many to many
                  if ($foreignField != $foreignTable->primaryKey) {
                      return false;
                      break;
                  }
  
                  // if foreign field is primary key of this table
                  // then it can not be many to many
                  if ($foreignField == $primary) {
                      return false;
                  }
              }
          }
  
          $modelName = model_name_from_table_name($manyToManyTable);
  
          return GeneratorFieldRelation::parseRelation('mtm,'.$modelName.','.$tableName);
      }
code_tokens: private function isManyToMany ( $ tables , $ tableName , $ modelTable , $ modelTableName ) { // get table details $ table = $ tables [ $ tableName ] ; $ isAnyKeyOnModelTable = false ; // many to many model table name $ manyToManyTable = '' ; $ foreignKeys = $ table -> foreignKeys ; $ primary = $ table -> primaryKey ; // check if any foreign key is there from model table foreach ( $ foreignKeys as $ foreignKey ) { if ( $ foreignKey -> foreignTable == $ modelTableName ) { $ isAnyKeyOnModelTable = true ; } } // if foreign key is there if ( $ isAnyKeyOnModelTable ) { foreach ( $ foreignKeys as $ foreignKey ) { $ foreignField = $ foreignKey -> foreignField ; $ foreignTableName = $ foreignKey -> foreignTable ; // if foreign table is model table if ( $ foreignTableName == $ modelTableName ) { $ foreignTable = $ modelTable ; } else { $ foreignTable = $ tables [ $ foreignTableName ] ; // get the many to many model table name $ manyToManyTable = $ foreignTableName ; } // if foreign field is not primary key of foreign table // then it can not be many to many if ( $ foreignField != $ foreignTable -> primaryKey ) { return false ; break ; } // if foreign field is primary key of this table // then it can not be many to many if ( $ foreignField == $ primary ) { return false ; } } } $ modelName = model_name_from_table_name ( $ manyToManyTable ) ; return GeneratorFieldRelation :: parseRelation ( 'mtm,' . $ modelName . ',' . $ tableName ) ; }
docstring: Detects many to many relationship
  If table has only two foreign keys
  Both foreign keys are primary key in foreign table
  Also one is from model table and one is from diff table.
  
  @param GeneratorTable[] $tables
  @param string           $tableName
  @param GeneratorTable   $modelTable
  @param string           $modelTableName
  
  @return bool|GeneratorFieldRelation
docstring_tokens: Detects many to many relationship If table has only two foreign keys Both foreign keys are primary key in foreign table Also one is from model table and one is from diff table .