@@ -45,6 +45,16 @@ trait MagicPropertiesTrait
4545 /** @psalm-var array<string, mixed> $propertyValues */
4646 private array $ propertyValues = [];
4747
48+ /**
49+ * Returns a value indicating whether the record has a relation query with the specified name.
50+ *
51+ * @param string $name The name of the relation query.
52+ */
53+ public function hasRelationQuery (string $ name ): bool
54+ {
55+ return method_exists ($ this , "get {$ name }Query " );
56+ }
57+
4858 /**
4959 * PHP getter magic method.
5060 * This method is overridden so that values and related objects can be accessed like properties.
@@ -74,7 +84,7 @@ public function __get(string $name)
7484 return $ this ->relatedRecords ()[$ name ];
7585 }
7686
77- if (method_exists ( $ this , " get { $ name} Query " )) {
87+ if ($ this -> hasRelationQuery ( $ name )) {
7888 /** Read relation query getter, e.g., getUserQuery() */
7989 return $ this ->retrieveRelation ($ name );
8090 }
@@ -142,7 +152,7 @@ public function __set(string $name, mixed $value): void
142152
143153 if (
144154 method_exists ($ this , "get $ name " )
145- || method_exists ( $ this , " get { $ name} Query " )
155+ || $ this -> hasRelationQuery ( $ name )
146156 ) {
147157 throw new InvalidCallException ('Setting read-only property: ' . static ::class . ':: ' . $ name );
148158 }
@@ -185,15 +195,15 @@ public function isProperty(string $name, bool $checkVars = true): bool
185195 {
186196 return method_exists ($ this , "get $ name " )
187197 || method_exists ($ this , "set $ name " )
188- || method_exists ( $ this , " get { $ name} Query " )
198+ || $ this -> hasRelationQuery ( $ name )
189199 || ($ checkVars && property_exists ($ this , $ name ))
190200 || $ this ->hasProperty ($ name );
191201 }
192202
193203 public function canGetProperty (string $ name , bool $ checkVars = true ): bool
194204 {
195205 return method_exists ($ this , "get $ name " )
196- || method_exists ( $ this , " get { $ name} Query " )
206+ || $ this -> hasRelationQuery ( $ name )
197207 || ($ checkVars && property_exists ($ this , $ name ))
198208 || $ this ->hasProperty ($ name );
199209 }
0 commit comments