Skip to content

Commit 638fda3

Browse files
authored
Using helper functions from command
1 parent 0883221 commit 638fda3

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

src/Utils/TableSorter.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,7 @@ private function getForeignKeyTables(\ReflectionClass $bean) : array
6262
$toReturn = [];
6363

6464
foreach ($bean->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
65-
$type = $property->getType();
66-
67-
if (!$type instanceof \ReflectionNamedType || $type->isBuiltin() || !\str_contains($property->getName(), '_')) {
68-
continue;
69-
}
70-
71-
$typeReflection = new \ReflectionClass($type->getName());
72-
73-
if (!$typeReflection->isSubclassOf(\CoolBeans\Contract\PrimaryKey::class)) {
65+
if (!\CoolBeans\Command\SqlGeneratorCommand::isForeignKeyColumn($property)) {
7466
continue;
7567
}
7668

@@ -100,9 +92,8 @@ private function getForeignKeyDependency(\ReflectionProperty $property) : ?strin
10092
return $foreignKey->table;
10193
}
10294

103-
$parts = \explode('_', $property->getName());
104-
\array_pop($parts);
95+
[$table, $column] = \CoolBeans\Command\SqlGeneratorCommand::getForeignKeyFromName($property->getName());
10596

106-
return \implode('_', $parts);
97+
return $table;
10798
}
10899
}

0 commit comments

Comments
 (0)