Skip to content

Commit

Permalink
oRm
Browse files Browse the repository at this point in the history
  • Loading branch information
dp committed Mar 25, 2015
1 parent 1749f98 commit 85e1a3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions Source/Ice/Core/Data/Scheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static function update(Module $module, $force = false)
$schemeTables[$tableName]['oneToManyHash'] = crc32(Json::encode([]));
}
$table['oneToManyHash'] = crc32(Json::encode($table['oneToMany']));
if ($table['oneToManyHash'] != $schemeTables[$tableName]['oneToManyHash']) {
if ($force || $table['oneToManyHash'] != $schemeTables[$tableName]['oneToManyHash']) {
$references = [];
foreach ($table['oneToMany'] as $referenceTableName => $columnName) {
$referenceClassName = isset($schemeTables[$referenceTableName])
Expand All @@ -187,7 +187,7 @@ public static function update(Module $module, $force = false)
$schemeTables[$tableName]['manyToOneHash'] = crc32(Json::encode([]));
}
$table['manyToOneHash'] = crc32(Json::encode($table['manyToOne']));
if ($table['manyToOneHash'] != $schemeTables[$tableName]['manyToOneHash']) {
if ($force || $table['manyToOneHash'] != $schemeTables[$tableName]['manyToOneHash']) {
$references = [];
foreach ($table['manyToOne'] as $referenceTableName => $columnName) {
$referenceClassName = isset($schemeTables[$referenceTableName])
Expand All @@ -207,8 +207,21 @@ public static function update(Module $module, $force = false)
$schemeTables[$tableName]['manyToManyHash'] = crc32(Json::encode([]));
}
$table['manyToManyHash'] = crc32(Json::encode($table['manyToMany']));
if ($table['manyToManyHash'] != $schemeTables[$tableName]['manyToManyHash']) {
Data_Scheme::getLogger()->info(['Update ManyToMany references for model {$0}: {$1}', [$schemeTables[$tableName]['modelClass'], Json::encode($table['references'])]]);
if ($force || $table['manyToManyHash'] != $schemeTables[$tableName]['manyToManyHash']) {
$references = [];
foreach ($table['manyToMany'] as $referenceTableName => $linkTableName) {
$referenceClassName = isset($schemeTables[$referenceTableName])
? $schemeTables[$referenceTableName]['modelClass']
: $module->getModelClass($referenceTableName, $dataSourceKey);

$linkClassName = isset($schemeTables[$linkTableName])
? $schemeTables[$linkTableName]['modelClass']
: $module->getModelClass($linkTableName, $dataSourceKey);

$references[$referenceClassName] = $linkClassName;
}
$table['manyToMany'] = $references;
Data_Scheme::getLogger()->info(['Update ManyToMany references for model {$0}: {$1}', [$schemeTables[$tableName]['modelClass'], Json::encode($table['manyToMany'])]]);
$schemeTables[$tableName]['manyToMany'] = $table['manyToMany'];
$schemeTables[$tableName]['manyToManyHash'] = $table['manyToManyHash'];
$updated = true;
Expand Down
2 changes: 1 addition & 1 deletion Source/Ice/Data/Source/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public function getTables(Module $module)
foreach ($data['references'] as $tableName1 => $reference1) {
foreach ($data['references'] as $tableName2 => $reference2) {
if ($tableName1 != $tableName2) {
$tables[$tableName1]['manyToMany'][] = $tableName2;
$tables[$tableName1]['manyToMany'][$tableName2] = $table['TABLE_NAME'];
}
}
}
Expand Down

0 comments on commit 85e1a3b

Please sign in to comment.