Skip to content

Commit

Permalink
DRY up code
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Jan 7, 2025
1 parent d66ac6b commit c7c9a76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
18 changes: 18 additions & 0 deletions src/Database/Concerns/HasReplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,22 @@ public function newReplicationInstance($attributes)

return $instance;
}

/**
* isRelationReplicable determines whether the specified relation should be replicated
*/
public function isRelationReplicable(string $name): bool
{
$relationType = $this->getRelationType($name);
if ($relationType === 'morphTo') {
return false;
}

$definition = $this->getRelationDefinition($name);
if (!array_key_exists('replicate', $definition)) {
return true;
}

return (bool) $definition['replicate'];
}
}
12 changes: 1 addition & 11 deletions src/Database/Replicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ protected function replicateRelationInternal($relationObject, $models)
*/
protected function isRelationReplicable(string $name): bool
{
$relationType = $this->model->getRelationType($name);
if ($relationType === 'morphTo') {
return false;
}

// Relation is shared via propagation
if (
!$this->isDuplicating &&
Expand All @@ -155,12 +150,7 @@ protected function isRelationReplicable(string $name): bool
return false;
}

$definition = $this->model->getRelationDefinition($name);
if (!array_key_exists('replicate', $definition)) {
return true;
}

return (bool) $definition['replicate'];
return $this->model->isRelationReplicable($name);
}

/**
Expand Down

0 comments on commit c7c9a76

Please sign in to comment.