change midKeys order for manyMany relation

This commit is contained in:
Taras Machyshyn
2013-12-26 17:53:51 +02:00
parent 842cddb0b1
commit caacabbf5c
2 changed files with 48 additions and 6 deletions
@@ -92,8 +92,8 @@ class Relations
'key' => 'id', //todo specify 'key'
'foreignKey' => 'id', //todo specify 'foreignKey'
'midKeys' => array(
$sortedEntities[0].'Id',
$sortedEntities[1].'Id',
lcfirst($params['entityName']).'Id',
lcfirst($foreignParams['entityName']).'Id',
),
),
),
@@ -260,7 +260,12 @@ class Relations
$relationKeys = explode('-', Util::fromCamelCase($params['link']['params']['relationName']));
$midKeys = array();
foreach($relationKeys as $key) {
$midKeys[] = $key.'Id';
/*if (strtolower($params['entityName']) == strtolower($key) || $key=='entity') {
$midKeys[0] = $key.'Id6666';
} else {
$midKeys[] = $key.'Id';
}*/
$midKeys[] = $key.'Id';
}
return array(
@@ -269,7 +274,7 @@ class Relations
$params['link']['name'] => array(
'type' => Entity::MANY_MANY,
'entity' => $params['targetEntity'],
'relationName' => $params['link']['params']['relationName'],
'relationName' => lcfirst($params['link']['params']['relationName']),
'midKeys' => $midKeys,
'conditions' => array('entityType' => $params['entityName']),
),
@@ -51,12 +51,15 @@ class Schema
}
//convertToSchema
public function process(array $databaseMeta, $entityDefs)
{
$GLOBALS['log']->add('Debug', 'Converters\Schema - Start: building schema');
//pre actions
$this->preProcess($databaseMeta, $entityDefs);
//END: pre actions
$schema = $this->getSchema();
$tables = array();
@@ -122,7 +125,7 @@ class Schema
//check for duplication tables
if (!isset($tables[$tableName])) { //no needs to create the table if it already exists
if ($tableName == 'EntityTeam') { //hardcode for Teams
if (strtolower($tableName) == strtolower('EntityTeam')) { //hardcode for Teams
if (isset($relationParams['conditions'])) {
$relationParams['midKeys'] = array_merge($relationParams['midKeys'], array_keys($relationParams['conditions']));
}
@@ -154,6 +157,20 @@ class Schema
}
protected function preProcess(array &$databaseMeta, &$entityDefs)
{
return;
/*echo '<pre>';
print_r($databaseMeta);
exit;*/
//hardcode for emails
$this->createEmailAddressTables();
//END: hardcode for emails
}
/**
* Prepare a relation table for the manyMany relation
*
@@ -172,6 +189,9 @@ class Schema
if ($isForeignKey) {
$relationEntities = array($entityName, $relationParams['entity']);
if (!isset($relationParams['key'])) {
print_r($relationParams);
}
$relationKeys = array($relationParams['key'], $relationParams['foreignKey']);
}
@@ -196,6 +216,23 @@ class Schema
return $table;
}
/*protected function getTableDefs($tableName)
{
$tableName = 'EmailAddress';
$table = $this->getSchema()->createTable( Util::toUnderScore($tableName) );
$table->addColumn('id', $this->idParams['dbType'], array('length'=>$this->idParams['len']));
switch ($tableName) {
case 'EmailAddress':
$primaryColumns[] = Util::toUnderScore($fieldName);
break;
case 'EntityEmailAddress':
$primaryColumns[] = Util::toUnderScore($fieldName);
break;
}
} */
protected function getDbFieldParams($fieldParams)
{