Skip to content

Commit b9fe25b

Browse files
authored
Improve tablesorter
1 parent 94c3983 commit b9fe25b

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/Utils/TableSorter.php

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

6464
foreach ($bean->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
65-
if (!$property->getType() instanceof \ReflectionNamedType) {
65+
$type = $property->getType();
66+
67+
if (!$type instanceof \ReflectionNamedType || $type->isBuiltin() || !\str_contains($property->getName(), '_')) {
6668
continue;
6769
}
6870

69-
$type = $property->getType();
70-
\assert($type instanceof \ReflectionNamedType);
71+
$typeReflection = new \ReflectionClass($type->getName());
72+
73+
if (!$typeReflection->isSubclassOf(\CoolBeans\Contract\PrimaryKey::class)) {
74+
continue;
75+
}
7176

7277
$foreignKeyTarget = $this->getForeignKeyDependency($property);
7378

@@ -95,10 +100,9 @@ private function getForeignKeyDependency(\ReflectionProperty $property) : ?strin
95100
return $foreignKey->table;
96101
}
97102

98-
if (!\str_ends_with($property->getName(), '_id')) {
99-
return null;
100-
}
103+
$parts = \explode('_', $property->getName());
104+
\array_pop($parts);
101105

102-
return \substr($property->getName(), 0, -3);
106+
return \implode('_', $parts);
103107
}
104108
}

0 commit comments

Comments
 (0)