1111use Tempest \Database \Relation ;
1212use Tempest \Database \Table ;
1313use Tempest \Database \Virtual ;
14+ use Tempest \Mapper \CastWith ;
15+ use Tempest \Mapper \SerializeWith ;
1416use Tempest \Reflection \ClassReflector ;
1517use Tempest \Reflection \PropertyReflector ;
1618use Tempest \Support \Arr \ImmutableArray ;
@@ -130,10 +132,18 @@ public function getBelongsTo(string $name): ?BelongsTo
130132 return $ belongsTo ;
131133 }
132134
135+ if ($ property ->hasAttribute (Virtual::class)) {
136+ return null ;
137+ }
138+
133139 if (! $ property ->getType ()->isRelation ()) {
134140 return null ;
135141 }
136142
143+ if ($ property ->hasAttribute (SerializeWith::class) || $ property ->getType ()->asClass ()->haSAttribute (SerializeWith::class)) {
144+ return null ;
145+ }
146+
137147 if ($ property ->hasAttribute (HasOne::class)) {
138148 return null ;
139149 }
@@ -189,6 +199,10 @@ public function getHasMany(string $name): ?HasMany
189199 return $ hasMany ;
190200 }
191201
202+ if ($ property ->hasAttribute (Virtual::class)) {
203+ return null ;
204+ }
205+
192206 if (! $ property ->getIterableType ()?->isRelation()) {
193207 return null ;
194208 }
@@ -199,6 +213,20 @@ public function getHasMany(string $name): ?HasMany
199213 return $ hasMany ;
200214 }
201215
216+ public function isRelation (string |PropertyReflector $ name ): bool
217+ {
218+ $ name = ($ name instanceof PropertyReflector) ? $ name ->getName () : $ name ;
219+
220+ return $ this ->getBelongsTo ($ name ) !== null || $ this ->getHasOne ($ name ) !== null || $ this ->getHasMany ($ name ) !== null ;
221+ }
222+
223+ public function getRelation (string |PropertyReflector $ name ): ?Relation
224+ {
225+ $ name = ($ name instanceof PropertyReflector) ? $ name ->getName () : $ name ;
226+
227+ return $ this ->getBelongsTo ($ name ) ?? $ this ->getHasOne ($ name ) ?? $ this ->getHasMany ($ name );
228+ }
229+
202230 public function getSelectFields (): ImmutableArray
203231 {
204232 if (! $ this ->isObjectModel ()) {
@@ -228,13 +256,6 @@ public function getSelectFields(): ImmutableArray
228256 return $ selectFields ;
229257 }
230258
231- public function getRelation (string |PropertyReflector $ name ): ?Relation
232- {
233- $ name = ($ name instanceof PropertyReflector) ? $ name ->getName () : $ name ;
234-
235- return $ this ->getBelongsTo ($ name ) ?? $ this ->getHasOne ($ name ) ?? $ this ->getHasMany ($ name );
236- }
237-
238259 public function resolveRelations (string $ relationString , string $ parent = '' ): array
239260 {
240261 if ($ relationString === '' ) {
0 commit comments