Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed Aug 8, 2023
1 parent 9adfb35 commit c652ad0
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Database/Concerns/HasReplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,9 @@ protected function replicateRelationsInternal(array $except = null, array $optio

foreach ($definitions as $type => $relations) {
foreach ($relations as $name => $options) {
if (!$this->isRelationReplicable($name)) {
continue;
if ($this->isRelationReplicable($name, $isMultisite, $isDuplicate)) {
$this->replicateRelationInternal($instance->$name(), $this->$name);
}

if (!$isDuplicate && $isMultisite && $this->isAttributePropagatable($name)) {
continue;
}

$this->replicateRelationInternal($instance->$name(), $this->$name);
}
}

Expand Down Expand Up @@ -113,13 +107,18 @@ protected function replicateRelationInternal($relationObject, $models)
* isRelationReplicable determines whether the specified relation should be replicated
* when replicateWithRelations() is called instead of save() on the model. Default: true.
*/
protected function isRelationReplicable(string $name): bool
protected function isRelationReplicable(string $name, bool $isMultisite, bool $isDuplicate): bool
{
$relationType = $this->getRelationType($name);
if ($relationType === 'morphTo') {
return false;
}

// Relation is shared via propagation
if (!$isDuplicate && $isMultisite && $this->isAttributePropagatable($name)) {
return false;
}

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

0 comments on commit c652ad0

Please sign in to comment.