Example #1
0
 /**
  * @param  string $withMappedFields
  * @param  array  $visited
  * @return array
  */
 private function getReferencesAsArray($withMappedFields, array &$visited)
 {
     $references = array();
     $tableName = $this->_table->getTableName();
     $relations = $this->_table->getRelations();
     foreach ($relations as $relation) {
         $refTable = $relation->getReferencedTable();
         $owningAlias = $relation->getOwningAlias();
         if ($tableName == $refTable && !isset($references[$owningAlias])) {
             $reference = $this->getReferenceAsArray($relation, $owningAlias, $withMappedFields, $visited);
             if ($reference !== false) {
                 $references[$owningAlias] = $reference;
             }
         }
         $owningTable = $relation->getOwningTable();
         $refAlias = $relation->getReferencedAlias();
         if ($tableName == $owningTable && !isset($references[$refAlias])) {
             $reference = $this->getReferenceAsArray($relation, $refAlias, $withMappedFields, $visited);
             if ($reference !== false && !isset($references[$refAlias])) {
                 $references[$refAlias] = $reference;
             }
         }
     }
     return $references;
 }
Example #2
0
 /**
  * @param Table $table
  * @param array $row
  * @return array
  */
 private function saveRequiredRelations(Table $table, array $row)
 {
     foreach ($table->getRelations() as $relationName => $relation) {
         $owning = $relation->getOwningField();
         if (!$relation->isReferencedSide($relationName) || isset($row[$relationName]) || isset($row[$owning])) {
             continue;
         }
         if ($table->isFieldRequired($owning)) {
             $row[$owning] = $this->saveRelatedRecord($relation->getReferencedTable(), null, array());
         }
     }
     return $row;
 }