File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments