@@ -108,6 +108,14 @@ public function getPropertyValues(): array
108108 $ values = [];
109109
110110 foreach ($ this ->reflector ->getProperties () as $ property ) {
111+ if ($ property ->isVirtual ()) {
112+ continue ;
113+ }
114+
115+ if ($ property ->hasAttribute (Virtual::class)) {
116+ continue ;
117+ }
118+
111119 if (! $ property ->isInitialized ($ this ->instance )) {
112120 continue ;
113121 }
@@ -247,6 +255,81 @@ public function getRelation(string|PropertyReflector $name): ?Relation
247255 return $ this ->getBelongsTo ($ name ) ?? $ this ->getHasOne ($ name ) ?? $ this ->getHasMany ($ name );
248256 }
249257
258+ /**
259+ * @return \Tempest\Support\Arr\ImmutableArray<array-key, Relation>
260+ */
261+ public function getRelations (): ImmutableArray
262+ {
263+ if (! $ this ->isObjectModel ()) {
264+ return arr ();
265+ }
266+
267+ $ relationFields = arr ();
268+
269+ foreach ($ this ->reflector ->getPublicProperties () as $ property ) {
270+ if ($ relation = $ this ->getRelation ($ property ->getName ())) {
271+ $ relationFields [] = $ relation ;
272+ }
273+ }
274+
275+ return $ relationFields ;
276+ }
277+
278+ /**
279+ * @return \Tempest\Support\Arr\ImmutableArray<array-key, PropertyReflector>
280+ */
281+ public function getValueFields (): ImmutableArray
282+ {
283+ if (! $ this ->isObjectModel ()) {
284+ return arr ();
285+ }
286+
287+ $ valueFields = arr ();
288+
289+ foreach ($ this ->reflector ->getPublicProperties () as $ property ) {
290+ if ($ property ->isVirtual ()) {
291+ continue ;
292+ }
293+
294+ if ($ property ->hasAttribute (Virtual::class)) {
295+ continue ;
296+ }
297+
298+ if ($ this ->isRelation ($ property ->getName ())) {
299+ continue ;
300+ }
301+
302+ $ valueFields [] = $ property ;
303+ }
304+
305+ return $ valueFields ;
306+ }
307+
308+ public function isRelationLoaded (string |PropertyReflector |Relation $ relation ): bool
309+ {
310+ if (! $ this ->isObjectModel ()) {
311+ return false ;
312+ }
313+
314+ if (! $ relation instanceof Relation) {
315+ $ relation = $ this ->getRelation ($ relation );
316+ }
317+
318+ if (! $ relation ) {
319+ return false ;
320+ }
321+
322+ if (! $ relation ->property ->isInitialized ($ this ->instance )) {
323+ return false ;
324+ }
325+
326+ if ($ relation ->property ->getValue ($ this ->instance ) === null ) {
327+ return false ;
328+ }
329+
330+ return true ;
331+ }
332+
250333 public function getSelectFields (): ImmutableArray
251334 {
252335 if (! $ this ->isObjectModel ()) {
@@ -266,13 +349,21 @@ public function getSelectFields(): ImmutableArray
266349 continue ;
267350 }
268351
352+ if ($ property ->getType ()->equals (PrimaryKey::class)) {
353+ continue ;
354+ }
355+
269356 if ($ relation instanceof BelongsTo) {
270357 $ selectFields [] = $ relation ->getOwnerFieldName ();
271358 } else {
272359 $ selectFields [] = $ property ->getName ();
273360 }
274361 }
275362
363+ if ($ primaryKey = $ this ->getPrimaryKeyProperty ()) {
364+ $ selectFields [] = $ primaryKey ->getName ();
365+ }
366+
276367 return $ selectFields ;
277368 }
278369
@@ -417,11 +508,11 @@ public function getPrimaryKeyProperty(): ?PropertyReflector
417508
418509 return match ($ primaryKeys ->count ()) {
419510 0 => null ,
420- 1 => $ primaryKeys ->first (),
421- default => throw ModelHadMultiplePrimaryColumns::found (
422- model: $ this ->model ,
423- properties: $ primaryKeys ->map (fn (PropertyReflector $ property ) => $ property ->getName ())->toArray (),
424- ),
511+ default => $ primaryKeys ->first (),
512+ // default => throw ModelHadMultiplePrimaryColumns::found(
513+ // model: $this->model,
514+ // properties: $primaryKeys->map(fn (PropertyReflector $property) => $property->getName())->toArray(),
515+ // ),
425516 };
426517 }
427518
0 commit comments