VersionPress\Utils\ReferenceUtils::getMnReferenceDetails PHP Method

getMnReferenceDetails() public static method

Returns complex info about the M:N reference. The source is always the given entity, target is the second one.
public static getMnReferenceDetails ( DbSchemaInfo $dbSchema, $entityName, $reference ) : array
$dbSchema VersionPress\Database\DbSchemaInfo
$entityName
$reference
return array The details has keys 'junction-table', 'source-entity', 'source-column', 'target-entity' and 'target-column'.
    public static function getMnReferenceDetails(DbSchemaInfo $dbSchema, $entityName, $reference)
    {
        list($junctionTable, $targetColumn) = explode(".", $reference);
        $targetEntity = $dbSchema->getEntityInfo($entityName)->mnReferences[$reference];
        $sourceColumn = self::getSourceColumn($dbSchema, $entityName, $targetEntity, $junctionTable);
        return ['junction-table' => $junctionTable, 'source-entity' => $entityName, 'source-column' => $sourceColumn, 'target-entity' => $targetEntity, 'target-column' => $targetColumn];
    }

Usage Example

 public function getAllMnReferences()
 {
     $mnReferences = [];
     foreach ($this->getAllEntityNames() as $entityName) {
         $entityInfo = $this->getEntityInfo($entityName);
         if (!$entityInfo->mnReferences) {
             continue;
         }
         foreach ($entityInfo->mnReferences as $reference => $targetEntity) {
             if ($entityInfo->isVirtualReference($reference)) {
                 continue;
             }
             $mnReferences[] = ReferenceUtils::getMnReferenceDetails($this, $entityName, $reference);
         }
     }
     return $mnReferences;
 }
All Usage Examples Of VersionPress\Utils\ReferenceUtils::getMnReferenceDetails