@@ -48,17 +48,23 @@ protected function getTableReflection(): ClassReflection
4848 */
4949 public function hasMethod (ClassReflection $ classReflection , string $ methodName ): bool
5050 {
51- // magic findBy* method
52- if ($ classReflection ->is (Table::class) && preg_match ('/^find(?:\w+)?By/ ' , $ methodName ) > 0 ) {
53- return true ;
51+ // Handle Table classes
52+ if ($ classReflection ->is (Table::class)) {
53+ if ($ classReflection ->hasNativeMethod ($ methodName )) {
54+ return false ; // Let the native method be used
55+ }
56+ // magic findBy* and findAllBy* methods - available on ALL table classes
57+ if (preg_match ('/^find(All)?By/ ' , $ methodName ) === 1 ) {
58+ return true ;
59+ }
5460 }
5561
5662 if (!$ classReflection ->is (Association::class)) {
5763 return false ;
5864 }
5965
60- // magic findBy* method on Association
61- if (preg_match ('/^find(?:\w+ )?By/ ' , $ methodName ) > 0 ) {
66+ // For associations, provide magic find(All)?By methods
67+ if (preg_match ('/^find(All )?By/ ' , $ methodName ) === 1 ) {
6268 return true ;
6369 }
6470
@@ -72,17 +78,19 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
7278 */
7379 public function getMethod (ClassReflection $ classReflection , string $ methodName ): MethodReflection
7480 {
75- // magic findBy* method
76- if ($ classReflection ->is (Table::class) && preg_match ('/^find(?:\w+)?By/ ' , $ methodName ) > 0 ) {
77- return new TableFindByPropertyMethodReflection ($ methodName , $ classReflection );
81+ // Handle Table classes
82+ if ($ classReflection ->is (Table::class)) {
83+ if ($ classReflection ->hasNativeMethod ($ methodName )) {
84+ return $ classReflection ->getNativeMethod ($ methodName );
85+ }
86+ // magic findBy* and findAllBy* methods
87+ if (preg_match ('/^find(All)?By/ ' , $ methodName ) === 1 ) {
88+ return new TableFindByPropertyMethodReflection ($ methodName , $ classReflection );
89+ }
7890 }
7991
80- // magic findBy* method on Association
81- $ associationReflection = $ this ->reflectionProvider ->getClass (Association::class);
82- if (
83- $ classReflection ->isSubclassOfClass ($ associationReflection )
84- && preg_match ('/^find(?:\w+)?By/ ' , $ methodName ) > 0
85- ) {
92+ // For associations, handle magic find(All)?By methods
93+ if (preg_match ('/^find(All)?By/ ' , $ methodName ) === 1 ) {
8694 return new TableFindByPropertyMethodReflection ($ methodName , $ this ->getTableReflection ());
8795 }
8896
0 commit comments