Skip to content

Commit

Permalink
Merge branch '3.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Jan 11, 2025
2 parents b26af0f + c7c9a76 commit 17a4110
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 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'];
}
}
2 changes: 1 addition & 1 deletion src/Database/Relations/AttachOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(Builder $query, Model $parent, $type, $id, $isPublic
public function setSimpleValue($value)
{
if (is_array($value)) {
$value = reset($value);
$value = current($value);
}

// Nulling the relationship
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Relations/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(Builder $query, Model $parent, $foreignKey, $localKe
public function setSimpleValue($value)
{
if (is_array($value)) {
return;
$value = current($value);
}

// Nulling the relationship
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Relations/MorphOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(Builder $query, Model $parent, $type, $id, $localKey
public function setSimpleValue($value)
{
if (is_array($value)) {
return;
$value = current($value);
}

// Nulling the relationship
Expand Down
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 17a4110

Please sign in to comment.