Exemplo n.º 1
0
 /**
  * Create a schema array for *-to-many associations
  *
  * @param array $sourceAssociation
  * @return ForestField|null
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 protected function getFieldForToManyAssociation($sourceAssociation)
 {
     $targetClassMetadata = $this->getClassMetadata($sourceAssociation['targetEntity']);
     $type = $this->getTypeForAssociation($sourceAssociation);
     $fieldName = $sourceAssociation['fieldName'];
     $inverseOf = $sourceAssociation['inversedBy'];
     $foreignTableName = $targetClassMetadata->getTableName();
     $foreignIdentifier = $targetClassMetadata->getIdentifier();
     //if(count($foreignIdentifier) > 1) die(__METHOD__.'::'.__LINE__.': '.$foreignTableName.' has more than one identifier : '.json_encode($foreignIdentifier));
     $foreignIdentifier = reset($foreignIdentifier);
     $reference = $foreignTableName . '.' . $foreignIdentifier;
     $field = new ForestField($fieldName, $type, $reference, $inverseOf);
     if (array_key_exists('joinTable', $sourceAssociation)) {
         if (!empty($sourceAssociation['joinTable'])) {
             $pivot = new Pivot($sourceAssociation['joinTable']['joinColumns'][0]['name'], $sourceAssociation['joinTable']['inverseJoinColumns'][0]['name'], $sourceAssociation['joinTable']['name']);
             $field->setPivot($pivot);
         }
     }
     return $field;
 }
Exemplo n.º 2
0
 /**
  * @param ForestField $field
  * @return bool|string
  * @throws CollectionNotFoundException
  */
 protected function findRelatedEntityClassName($field)
 {
     $relationName = $field->getReferencedTable();
     if ($relationName) {
         foreach ($this->getCollections() as $collection) {
             if ($collection->getName() == $relationName) {
                 return $collection->getEntityClassName();
             }
         }
         throw new CollectionNotFoundException($relationName);
     }
     return false;
 }