VersionPress\Utils\ReferenceUtils::getSourceColumn PHP Method

getSourceColumn() private static method

Example: We are synchronizing posts with M:N reference to the taxonomies. The reference is defined as term_relationships.term_taxonomy_id => term_taxonomy. Name of column referencing term_taxonomy is obvious, it's term_taxonomy_id. However we need also name of column referencing the post. We can find this name in the definition of M:N references of term_taxonomy, where it's defined as term_relationships.object_id => post. So in the end we are looking for M:N reference to post with same junction table (term_relationships).
private static getSourceColumn ( DbSchemaInfo $dbSchema, $sourceEntity, $targetEntity, $junctionTable ) : string
$dbSchema VersionPress\Database\DbSchemaInfo
$sourceEntity
$targetEntity
$junctionTable
return string
    private static function getSourceColumn(DbSchemaInfo $dbSchema, $sourceEntity, $targetEntity, $junctionTable)
    {
        $targetEntityMnReferences = $dbSchema->getEntityInfo($targetEntity)->mnReferences;
        foreach ($targetEntityMnReferences as $reference => $referencedEntity) {
            list($referencedTable, $referenceColumn) = explode(".", $reference);
            if ($referencedTable === $junctionTable && $referencedEntity === $sourceEntity) {
                return $referenceColumn;
            }
        }
        return null;
    }