예제 #1
0
 /**
  * Generate parents records using the relationship defined in links.ini file
  *
  * @param DB_DataObject $do
  */
 function generateParents(&$do)
 {
     $links = $do->links();
     foreach ($links as $foreignKey => $linkedTableField) {
         if (!empty($do->{$foreignKey})) {
             // parent is already set
             continue;
         }
         list($linkedTable, $linkedField) = explode(':', $linkedTableField);
         $table = $do->getTableWithoutPrefix($linkedTable);
         $linkedPrimaryKeyVal = isset($do->{$foreignKey}) ? $do->{$foreignKey} : null;
         if (!empty($this) && is_a($this, 'DataGenerator')) {
             $do->{$foreignKey} = $this->addAncestor($table, $linkedPrimaryKeyVal);
         } else {
             $do->{$foreignKey} = DataGenerator::addAncestor($table, $linkedPrimaryKeyVal);
         }
     }
 }