Skip to content

Commit c41771d

Browse files
refactor(relationships): replace 'source' references with 'snapshotSource' for consistency and clarity in HasSnapshot
1 parent f5a31e8 commit c41771d

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/Concerns/HasSnapshot.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static function bootHasSnapshot()
110110
foreach ($syncedSourceRelationships as $relationship) {
111111
if(!method_exists(static::class, $relationship)){
112112
static::resolveRelationUsing($relationship, function ($snapshotable) use ($sourceInstance, $relationship) {
113-
$source = $snapshotable->source;
113+
$source = $snapshotable->snapshotSource;
114114

115115
if($source){
116116
return $source->{$relationship}();
@@ -120,13 +120,6 @@ public static function bootHasSnapshot()
120120
});
121121
}
122122
}
123-
124-
// if(method_exists($sourceInstance, 'definedRelationsTypes')){
125-
// }
126-
127-
// static::resolveRelationUsing('source', function ($model) {
128-
// return $model->hasOneThrough(Snapshot::class, Snapshot::class, 'snapshotable_id', 'id', 'id', 'source_id');
129-
// });
130123
}
131124

132125
/**
@@ -186,7 +179,7 @@ protected function getSnapshotSource()
186179
return $class::find($sourceModelOwnerId);
187180
}
188181

189-
return $this->source;
182+
return $this->snapshotSource;
190183
}
191184

192185
/**
@@ -198,7 +191,7 @@ protected function getSnapshotSource()
198191
public function prepareDataToSnapshot(): array
199192
{
200193
$sourceRelationships = $this->getSourceRelationshipsToSnapshot();
201-
$source = $this->getSnapshotSource();
194+
$source = $this->snapshotSource()->with($sourceRelationships)->first();
202195

203196
foreach($sourceRelationships as $relationship){
204197
$source->load($relationship);
@@ -373,9 +366,9 @@ public function attributesToArray(): array
373366
{
374367
$attributes = parent::attributesToArray();
375368

376-
$source = $this->relationLoaded('source')
377-
? $this->getRelation('source')
378-
: $this->source;
369+
$source = $this->relationLoaded('snapshotSource')
370+
? $this->getRelation('snapshotSource')
371+
: $this->snapshotSource;
379372

380373
$snapshot = $this->snapshot;
381374

@@ -438,9 +431,9 @@ public function __get($key)
438431
return $snapshot->source_id;
439432
}
440433

441-
$source = $this->relationLoaded('source')
442-
? $this->getRelation('source')
443-
: $this->source;
434+
$source = $this->relationLoaded('snapshotSource')
435+
? $this->getRelation('snapshotSource')
436+
: $this->snapshotSource;
444437

445438
if($this->fieldIsSnapshotSynced($key)){
446439
if($source){
@@ -523,9 +516,9 @@ public function __call($method, $parameters)
523516

524517
if($methodReflector->hasReturnType() && preg_match("{$relationClassesPattern}", $methodReflector->getReturnType() )){
525518

526-
$source = $this->relationLoaded('source')
527-
? $this->getRelation('source')
528-
: $this->source;
519+
$source = $this->relationLoaded('snapshotSource')
520+
? $this->getRelation('snapshotSource')
521+
: $this->snapshotSource;
529522

530523
$query = $source->{$method}();
531524

0 commit comments

Comments
 (0)